-
Notifications
You must be signed in to change notification settings - Fork 159
/
Copy path1692D-TheClock.cpp
40 lines (31 loc) · 910 Bytes
/
1692D-TheClock.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <set>
const long B = 24 * 60;
bool isPalin(long x){
const long h = x / 60;
const long m = x % 60;
return ((h / 10) == (m % 10)) && ((h % 10) == (m / 10));
}
long convert(std::string x){
return (10 * 60 * (x[0] - '0') + 60 * (x[1]- '0') + 10 * (x[3] - '0') + (x[4] - '0'));
}
int main(){
std::set<long> palins;
for(long min = 0; min < B; min++){
if(isPalin(min)){palins.insert(min);}
}
std::ios_base::sync_with_stdio(false);
long t; std::cin >> t;
while(t--){
std::string s; long interval;
std::cin >> s >> interval;
long start = convert(s);
long cur(start), cnt(palins.count(start));
for(long p = 1; p < B; p++){
cur += interval; cur %= B;
if(cur == start){break;}
cnt += palins.count(cur);
}
std::cout << cnt << std::endl;
}
}