CSU1626: Time Warp

Description

CSU1626: Time Warp_第1张图片

Input

Output

Sample Input

4
20 after 8
126 til 4
180 til 1
0 after 12

Sample Output

Case 1: 8:47:16
Case 2: 3:39:16
Case 3: 12:32:44
Case 4: 1:05:27

HINT

Source



#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <math.h>
#include <bitset>
#include <algorithm>
#include <climits>
using namespace std;

#define LS 2*i
#define RS 2*i+1
#define UP(i,x,y) for(i=x;i<=y;i++)
#define DOWN(i,x,y) for(i=x;i>=y;i--)
#define MEM(a,x) memset(a,x,sizeof(a))
#define W(a) while(a)
#define LL long long
#define N 25
#define MOD 19999997
#define INF 0x3f3f3f3f
#define EXP 1e-8

int t,hour,a,b,r,cas=1,m,s;
double minute,second;
char str[10];

void setA()
{
    if(r<=0)
        r+=360;
    minute = r/5.5;
    W(minute>=60)
    {
        hour++;
        minute-=60;
    }
    if(hour>12)
        hour-=12;
    m = (int)minute;
}

void setT()
{
    if(r>=0) r-=360;
    minute=r/5.5;
    hour--;
    W(minute<=-60)
    {
        hour--;
        minute+=60;
    }
    if(hour<=0)
        hour+=12;
    if(fabs(minute)<=EXP)
    {
        hour++;
        if(hour>12)
            hour-=12;
    }
    else minute+=60;
    m = (int)minute;
}

int main()
{
    scanf("%d",&t);
    W(t--)
    {
        scanf("%d%s%d",&a,str,&hour);
        b = 30*(12-hour);
        r = a-b;
        if(str[0]=='a')
            setA();
        else
            setT();
        second = (minute-(int)minute)*60;
        s = (int)(second+0.5);
        printf("Case %d: %d:%02d:%02d\n",cas++,hour,m,s);
    }


    return 0;
}


你可能感兴趣的:(CSU)