-
Notifications
You must be signed in to change notification settings - Fork 0
/
1b.cpp
78 lines (71 loc) · 1.34 KB
/
1b.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
77
78
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
void fun1(string &s) {
int col = 0;
int row = 0;
size_t i = 0;
while ('A' <= s[i] && s[i] <= 'Z') {
col *= 26;
col += s[i]-'A'+1;
i++;
}
while (i < s.size()) {
row *= 10;
row += s[i]-'0';
i++;
}
cout << 'R' << row << 'C' << col << endl;
}
void fun2(string &s) {
int col = 0;
int row = 0;
size_t i = 1;
while (i < s.size() && '0' <= s[i] && s[i] <= '9') {
row *= 10;
row += s[i]-'0';
i++;
}
if (row == 0) {
fun1(s);
return ;
}
if (i == s.size()) {
cout << 'R' << row << 'C' << 18 << endl;
return ;
}
i++;
while (i < s.size()) {
col *= 10;
col += s[i]-'0';
i++;
}
string scol;
while (col) {
if (col%26 == 0) {
scol.push_back('Z');
col /= 26;
col--;
}
else {
scol.push_back('A'+col%26-1);
col /= 26;
}
}
reverse(scol.begin(), scol.end());
cout << scol << row << endl;
}
int main() {
int n;
cin >> n;
while (n--) {
string s;
cin >> s;
if (s[0] != 'R')
fun1(s);
else
fun2(s);
}
return 0;
}