-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1B.cpp
More file actions
66 lines (64 loc) · 1.67 KB
/
1B.cpp
File metadata and controls
66 lines (64 loc) · 1.67 KB
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
#include<iostream>
#include<string>
using namespace std;
int main() {
int n;
cin>>n;
for(int i=0;i<n;i++) {
string s;
cin>>s;
int flag = 0;
int type = 0;
for(int j = 0; j < s.length(); j++) {
if(s[j] >= '0' && s[j] <= '9') {
flag = 1;
}
if(flag == 1 && s[j] >= 'A' && s[j] <= 'Z') {
type = 1;
break;
}
}
if(type == 0) {
int r = 0, c = 0;
for(int j = 0; j < s.length(); j++) {
if(s[j] >= 'A' && s[j] <= 'Z') {
c *= 26;
c+=s[j]-'A'+1;
} else {
r*=10;
r+=s[j]-'0';
}
}
cout<<"R"<<r<<"C"<<c<<endl;
} else {
int r = 0, c = 0;
int flag = 0;
for(int j = 0; j < s.length(); j++) {
if(s[j] == 'C') {
flag = 1;
} else if(s[j] != 'R') {
if(flag==0) {
r*=10;
r+=s[j]-'0';
} else {
c*=10;
c+=s[j]-'0';
}
}
}
string sc = "";
int k = 1;
int s = 1;
int n = 0;
while(c >= s) { k *= 26; s += k; sc+="A";}
s -= k;
k /= 26;
c -= s;
for(int j = 0;c!=0;j++) {
sc[sc.length() - j - 1] = (char)(c%26+'A');
c/=26;
}
cout<<sc<<r<<endl;
}
}
}