Codeforces Round #799 (Div. 4)D. The Clock

42 篇文章 0 订阅

Victor has a 24-hour clock that shows the time in the format "HH:MM" (00 ≤≤ HH ≤≤ 23, 00 ≤≤ MM ≤≤ 59). He looks at the clock every xx minutes, and the clock is currently showing time ss.

How many different palindromes will Victor see in total after looking at the clock every xx minutes, the first time being at time ss?

For example, if the clock starts out as 03:12 and Victor looks at the clock every 360360 minutes (i.e. every 66 hours), then he will see the times 03:12, 09:12, 15:12, 21:12, 03:12, and the times will continue to repeat. Here the time 21:12 is the only palindrome he will ever see, so the answer is 11.

A palindrome is a string that reads the same backward as forward. For example, the times 12:21, 05:50, 11:11 are palindromes but 13:13, 22:10, 02:22 are not.

Input

The first line of the input contains an integer tt (1≤t≤1001≤t≤100) — the number of test cases. The description of each test case follows.

The only line of each test case contains a string ss of length 55 with the format "HH:MM" where "HH" is from "00" to "23" and "MM" is from "00" to "59" (both "HH" and "MM" have exactly two digits) and an integer xx (1≤x≤14401≤x≤1440) — the number of minutes Victor takes to look again at the clock.

Output

For each test case, output a single integer — the number of different palindromes Victor will see if he looks at the clock every xx minutes starting from time ss.

Example

input

Copy

6
03:12 360
00:00 1
13:22 2
15:15 10
11:11 1440
22:30 27

output

Copy

1
16
10
0
1
1

思路:这题唯一的坑点就是他会一直持续到第二天第三天等等,走完所有不同的时间之后最终会和直接刚开始的时刻相等,所以我们在算的时候正常算,把跳出循环的条件设成刚开始的时刻就行。(注意小时在算的时候是24计时,所以每次我们要%24)

#include<iostream>
#include<algorithm>
#include<cstring>

using namespace std;

int hh,mm,num;
int h,m;
bool cheek(int a,int b){
	if(a/10==b%10&&a%10==b/10){
		return true;
	}
	return false;
}
int tm,th;
void sove(){
	scanf("%d:%d",&hh,&mm);
	scanf("%d",&num);
	h=hh;
	m=mm;
	tm=num%60;
	th=num/60;
	int ans=0;
	while(1){
		hh=((hh+th)+(mm+tm)/60)%24;
		mm=(mm+tm)%60;
		if(cheek(hh,mm)){
			ans++;
		}
		if(hh==h&&mm==m)break;
	}
	printf("%d\n",ans);
}
int main(){
	int t;
	cin>>t;
	while(t--){
		sove();
	}
	return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值