问题 B: Niuniu’s Clock

时间限制: 1 Sec 内存限制: 128 MB

提交 状态 题面

题目描述

Niuniu has a clock with two hands, an hour hand and a minute hand. Sometimes it looks like just having one hand because the two hands coincide. Niuniu wants to know how many times the two hands coincide from A’o clock to B’o clock (0≤A<B≤24). (If the two hands coincide at A’o clock, it will be counted. But coincidence will not be counted at B’o clock.)

输入

Read from the standard input.

The first line contains an integer T (0 ≤ T ≤ 300) which is the number of cases.

The next T lines give two integers A and B for each case.

输出

Write to the standard output.

Output T lines, each line containing an integer as the answer of each case.

样例输入

1

14 17

样例输出

3

提示

From 14’o clock to 17’o clock, the two hands coincide three times at about 14:11,15:16 and 16:22 respectively.

#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    int t;
    cin>>t;
    while (t--) {
        int A,B;
        scanf ("%d%d",&A,&B);
        if(A<12) {
            if(B<12) {
                printf ("%d\n",B-A);
            }
            else if(B>=12) {
                if(B==24) printf ("%d\n",B-A-2);
                else printf ("%d\n",B-A-1);
            }
        }
        else if(A>=12) {
            if(B==24) printf ("%d\n",B-A-1);
            else printf ("%d\n",B-A);
        }
    }
    return 0;
}

留下评论

通过 WordPress.com 设计一个这样的站点
从这里开始