forked from buglinjo/codeforces
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1B - Spreadsheet.cpp
76 lines (71 loc) · 1.6 KB
/
1B - Spreadsheet.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
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
75
76
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <string>
using namespace std;
string getY(int y) {
string str;
int num = y / 26;
int nash = y % 26;
if (nash == 0) {
str = (char)(nash + 26 + 64);
num--;
} else {
str = (char)(nash + 64);
}
if (num == 0) {
return str;
} else {
return getY(num) + str;
}
}
string intToStr(string x, int y) {
return getY(y) + x;
}
string getX(string x) {
int ans = 0, num;
for (int i = 0, j = x.size() - 1; i < x.size(), j >= 0; i++, j--) {
num = x[j] - 64;
num = num * round(pow(26, i));
ans += num;
}
return to_string(ans);
}
string strToInt(string x, string y) {
return 'R' + y + 'C' + getX(x);
}
int n, c, xi, yi;
string a, x, y;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
x = "";
y = "";
cin >> a;
c = 0;
if (a[0] == 'R') {
for (int j = 1; j < a.size(); j++) {
if (a[j] == 'C') {
c = 1;
} else {
if (c == 0) {
x += a[j];
} else {
y += a[j];
}
}
}
yi = stoi(y);
cout << intToStr(x, yi) << endl;
} else {
for (int j = 0; j < a.size(); j++) {
if (a[j] < 65) {
y += a[j];
} else {
x += a[j];
}
}
cout << strToInt(x, y) << endl;
}
}
}