-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCF1B.cpp
94 lines (94 loc) · 1.33 KB
/
CF1B.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include<iostream>
#include<string>
#include<stack>
using namespace std;
int n;
void change1(string str) {
int a1 = 0;
int a2 = 0;
int i = 1;
char c = str[i];
while (true) {
int it = c - '0';
a1 *= 10;
a1 += it;
c = str[++i];
if ((c > '9') || (c < '0')) {
break;
}
}
i++;
while (i < str.size()) {
c = str[i++];
a2 *= 10;
int it = c - '0';
a2 += it;
}
stack<char> mystack;
while (a2) {
int it = a2 % 26;
a2 /= 26;
char c;
if (!it) {
c = 'Z';
a2--;
}
else {
c = 'A' + it - 1;
}
mystack.push(c);
}
while (!mystack.empty()) {
cout << mystack.top();
mystack.pop();
}
cout << a1 << endl;
}
void change2(string str) {
int i = 0;
int a1 = 0;
int a2 = 0;
char c = str[i];
while (true) {
int it = c - 'A' + 1;
a1 *= 26;
a1 += it;
c = str[++i];
if ((c < 'A') || (c > 'Z')) {
break;
}
}
while (i < str.size()) {
c = str[i++];
int it = c - '0';
a2 *= 10;
a2 += it;
}
cout << 'R' << a2 << 'C' << a1 << endl;
}
void test() {
string str;
cin >> str;
bool flag = 0;
for (int i = 1;i < str.size();i++) {
if ((str[i - 1] >= '0') && (str[i - 1] <= '9') && (str[i] >= 'A') && (str[i]) <= 'Z') {
flag = 1;
}
else {
continue;
}
}
if (flag) {
change1(str);
}
else {
change2(str);
}
}
int main() {
cin >> n;
for (int i = 0;i < n;i++) {
test();
}
return 0;
}