-
Notifications
You must be signed in to change notification settings - Fork 0
/
B.cpp
118 lines (115 loc) · 3.13 KB
/
B.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include<bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(0);cin.tie(0)
int main()
{
fastio;
string s;
long long t,i,n;
cin>>t;
while(t--)
{
cin>>s;
n=s.size();
if(s[0]=='R')
{
if(s[1]>='A' && s[1]<='Z')
{
long long col=0;
string row;
for(i=0;i<n;i++)
{
if(s[i]>='A' && s[i]<='Z')
{
col=(col*26)+(s[i]-'A'+1);
}
else
{
row.push_back(s[i]);
}
}
cout<<"R"<<row<<"C"<<col<<"\n";
}
else
{
int flag=0;
for(i=2;i<n;i++)
{
if(s[i]=='C')
{
flag=1;
break;
}
}
if(flag==0)
{
long long col=0;
string row;
for(i=0;i<n;i++)
{
if(s[i]>='A' && s[i]<='Z')
{
col=(col*26)+(s[i]-'A'+1);
}
else
{
row.push_back(s[i]);
}
}
cout<<"R"<<row<<"C"<<col<<"\n";
}
else
{
string row,colstr;
long long idx,col=0;
for(i=1;i<n;i++)
{
if(s[i]=='C')
{
idx=i;
break;
}
row.push_back(s[i]);
}
for(i=idx+1;i<n;i++)
col=(col*10)+(s[i]-'0');
long long ext=0;
while(col!=0)
{
if(col%26==0){
colstr.push_back('Z');
ext=1;
col/=26;
col--;
}
else{
colstr.push_back('A'+(col%26)-1);
ext=0;
col/=26;
}
//col/=26;
}
reverse(colstr.begin(),colstr.end());
cout<<colstr<<row<<"\n";
}
}
}
else
{
long long col=0;
string row;
for(i=0;i<n;i++)
{
if(s[i]>='A' && s[i]<='Z')
{
col=(col*26)+(s[i]-'A'+1);
}
else
{
row.push_back(s[i]);
}
}
cout<<"R"<<row<<"C"<<col<<"\n";
}
}
}