-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCryptopangrams (10pts, 15pts).cpp
More file actions
74 lines (66 loc) · 1.41 KB
/
Cryptopangrams (10pts, 15pts).cpp
File metadata and controls
74 lines (66 loc) · 1.41 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
65
66
67
68
69
70
71
72
73
74
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <cstdio>
#include <set>
#include <unordered_map>
using namespace std;
long a[101];
long list[101];
set<long> s;
unordered_map<long, int> um;
long gcd(long a,long b)
{
if(a%b==0)
return b;
else
return gcd(b,a%b);
}
void solve() {
memset(a, 0, sizeof(a));
memset(list, 0, sizeof(a));
s.clear();
um.clear();
long N, L;
cin >> N >> L;
for(long i = 0; i < L; ++i) {
long tmp;
cin >> tmp;
a[i] = tmp;
}
for(long i = 1; i < L; ++i) {
if(a[i] == a[i - 1]) continue;
list[i] = gcd(a[i], a[i - 1]);
int j = i - 1;
while(j >= 0 && list[j] == 0) {
list[j] = a[j] / list[j + 1];
--j;
}
j = i + 1;
while(j < L + 1 && list[j] == 0) {
list[j] = a[j - 1] / list[j - 1];
++j;
}
break;
}
for(long i = 0; i < L + 1; ++i) s.emplace(list[i]);
int c = 0;
for(auto it = s.begin(); it != s.end(); ++it) um[*it] = c++;
for(long i = 0; i < L + 1; ++i) {
char cc = 'A' + um[list[i]];
cout << cc;
}
cout << endl;
}
int main() {
//freopen("../in", "r", stdin);
//freopen("../out", "w", stdout);
int T;
cin >> T;
for(int i = 1; i <= T; ++i) {
printf("Case #%d: ", i);
solve();
}
return 0;
}