天天看点

CDOJ Clock

Clock

Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others)

Submit Status

Clock is invented by ancient Arabic engineers and which contributes to build the concept of accurate time for us human beings and even could be essential tool that widely used in industry, business and our routine lives. Nevertheless, the ideology of clock turns out to be quite simply that even make sense to little kids. We could hardly imagine that how do Arabic wisdom come up with such idea to indicate time only by two or three fingers. The other day, hhb are asking lxh and Hysramp to play his newly invented game describe as follow. hhb randomly change the time of his lovely alarm clock then ask lxh and Hysramp to tell the degree between hour finger and minute finger. lxh seems quite gifted playing it while Hysramp does not. When Hysramp fails to answer hhb, hhb smiles to Hysramp. And Hysramp smiles to you, an ace programmer.

Input

The first line of the input contains one integer T, which indicate the number of test cases. Each test case contains one indicating the time on hhb’s clock in the form of HH:MM. (0≤HH<24,0≤MM<60)

Output

One line for each test case contains only one number indicating the answer. An integer or an irreducible fraction indicated the degree between hour finger and minute finger.

Sample input and output

Sample Input Sample Output

1

00:00

Source

电子科技大学第七届ACM程序设计大赛 初赛

http://www.acm.uestc.edu.cn/#/problem/show/49

#include<stdio.h>
int main()
{
    int t,p, hh,mm, sh,sm,  res;
    scanf("%d",&t);
    for (p=;p<=t;p++)
    {
        scanf("%d:%d",&hh,&mm);
        if (hh>=)
            hh=hh-;
        sh=hh*60+mm;
        sm=mm*12;
        if (sh>sm) res=sh-sm;
        else res=sm-sh;
        if (res>=) res=-res;
        if (res%2==) printf("%d\n",res/);
        else printf("%d/2\n",res);
    }
    return ;
}
           
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <string>
#include <numeric>
#include <algorithm>
#include <functional>
#include <iterator>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <complex>
#include <ctime>

typedef long long LL;

const double pi = acos(-);
const long long mod =  + ;

using namespace std;

int main()
{
    //freopen("int.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int T, H, M, ans;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d:%d",&H,&M);
        if(H >= )
            H = H - ;
         ans = abs(  * H -  * M );
        if(ans >= )
            ans =  - ans;
        if(ans %  == )
            printf("%d\n",ans / );
        else
            printf("%d/2\n",ans);
    }
    return ;
}