-
Notifications
You must be signed in to change notification settings - Fork 0
/
P17269.cpp
49 lines (41 loc) · 1.05 KB
/
P17269.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
41
42
43
44
45
46
47
48
49
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
int DATA[26] = {3, 2, 1, 2, 4, 3, 1, 3, 1, 1, 3, 1, 3, 2, 1, 2, 2, 2, 1, 2, 1, 1, 1, 2, 2, 1};
vector<int> vec;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int N, M; cin >> N >> M;
string A, B; cin >> A >> B;
int i;
int len_min = min(N, M);
int len_max = max(N, M);
for (i = 0; i < len_min; i++) {
vec.push_back(DATA[A[i] - 'A']);
vec.push_back(DATA[B[i] - 'A']);
}
for (int j = i; j < len_max; j++) {
if (N > M) {
vec.push_back(DATA[A[j] - 'A']);
} else {
vec.push_back(DATA[B[j] - 'A']);
}
}
while(true) {
if (vec.size() == 2) {
cout << 10 * vec[0] + vec[1] << "%";
break;
}
vector<int> tmp;
for (int j = 0; j < vec.size() - 1; ++j) {
tmp.push_back((vec[j] + vec[j + 1]) % 10);
}
vec = tmp;
tmp.clear();
}
return 0;
}