-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1B.cpp
68 lines (48 loc) · 1.69 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
#include<bits/stdc++.h>
using namespace std;
long convertToNumeric(string input){
long output(0);
const int alphaSize(26);
for(int k = 0; k < input.size(); k++){output = alphaSize * output + (input[k] - 'A' + 1);}
return output;
}
string convertToAlpha(long input){
const int alphaSize(26);
string output("");
while(input > 0){
char letter = 'Z';
long inputMod = input % alphaSize;
if(inputMod > 0){letter = 'A' + inputMod - 1;}
else{input -= alphaSize;}
input = input / alphaSize;
output = letter + output;
}
return output;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n; scanf("%d\n", &n);
while(n--){
string line; getline(cin, line);
bool coordinates(0);
if(line[0] == 'R' && ('0' <= line[1] && line[1] <= '9') && 1 < line.find('C') && line.find('C') < line.size() - 1){coordinates = 1;}
if(coordinates){
int cPos = line.find('C');
string rowString = line.substr(1, cPos - 1);
string colString = line.substr(cPos + 1);
long col = atol(colString.c_str());
cout << convertToAlpha(col) << rowString << endl;
}
else{
string rowString = "";
string colString = "";
for(int k = 0; k < line.size(); k++){
if('0' <= line[k] && line[k] <= '9'){colString = line.substr(k);break;}
else{rowString += line[k];}
}
cout << "R" << colString << "C" << convertToNumeric(rowString) << endl;
}
}
return 0;
}