-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathround1_Spreadsheets.cpp
72 lines (68 loc) · 1.9 KB
/
round1_Spreadsheets.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
#include <iostream>
#include <ctype.h>
using namespace std;
bool is_RC(string& s) {
if(s[0] == 'R' && isdigit(s[1]))
{
for (int i = 2; i < s.size(); i++)
if (s[i] == 'C')
return true;
}
return false;
}
int main() {
int n;
while (cin >> n) {
int line, column;
bool C_appear;
for (int i = 0; i < n; i++) {
int line, column;
C_appear = false;
string s;
cin >> s;
if (is_RC(s)) {
line = 0;
column = 0;
string result = "";
for (char c : s) {
if (c == 'R')
continue;
if (c == 'C') {
C_appear = true;
continue;
}
if (!C_appear)
line = (c-'0') + line*10;
else
column = (c-'0') + column*10;
}
while (column != 0) {
if (column % 26 == 0) {
result.insert(0, 1, 'Z');
column = column/26-1;
}
else {
result.insert(0, 1, char('A'+column%26-1));
column = column/26;
}
}
cout << result << line << endl;
}
else {
line = 0;
column = 0;
int i = 0;
while (isalpha(s[i])) {
column = s[i]-'A'+1 + column*26;
i++;
}
while (i < s.size()) {
line = s[i]-'0'+line*10;
i++;
}
cout << 'R' << line << 'C' << column << endl;
}
}
}
return 0;
}