forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC.cpp
More file actions
64 lines (58 loc) · 1.22 KB
/
Copy pathC.cpp
File metadata and controls
64 lines (58 loc) · 1.22 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
#include <sstream>
#include <string>
#include <cstring>
#include <map>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
int s2i(string s) {
stringstream ss;
ss << s;
int res;
ss >> res;
return res;
}
string i2s(int n) {
stringstream ss;
ss << n;
string res;
ss >> res;
return res;
}
int v[2000005];
void run() {
int A, B;
cin >> A >> B;
memset(v, 0, sizeof(v));
int ret = 0;
string sa = i2s(A), sb = i2s(B);
FOR(n,A,B) {
if (v[n] == 1) continue;
string str = i2s(n);
int len = str.length();
int cnt = 0;
REP(i,len) {
if (str[i] < sa[0] || str[i] > sb[0]) continue;
string ts = str.substr(i) + str.substr(0, i);
int ti = s2i(ts);
if (ti >= A && ti <= B) {
if (v[ti] == 0) {
++cnt;
v[ti] = 1;
} else break;
}
}
if (cnt >= 2) ret += cnt * (cnt - 1) / 2;
}
cout << ret << endl;
}
int main() {
int k;
cin >> k;
FOR(c,1,k) {
cout << "Case #" << c << ": ";
run();
}
return 0;
}