In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till column 26 that is marked by Z. Then there are two-letter numbers: column 27 has number AA, 28 — AB, column 52 is marked by AZ. After ZZ there follow three-letter numbers, etc.
The rows are marked by integer numbers starting with 1. The cell name is the concatenation of the column and the row numbers. For example, BC23 is the name for the cell that is in column 55, row 23.
Sometimes another numeration system is used: RXCY, where X and Y are integer numbers, showing the column and the row numbers respectfully. For instance, R23C55 is the cell from the previous example.
Your task is to write a program that reads the given sequence of cell coordinates and produce each item written according to the rules of another numeration system.
Input
The first line of the input contains integer number n (1 ≤ n ≤ 105), the number of coordinates in the test. Then there follow n lines, each of them contains coordinates. All the coordinates are correct, there are no cells with the column and/or the row numbers larger than 106 .
Output
Write n lines, each line should contain a cell coordinates in the other numeration system.
Example
2
R23C55
BC23
BC23
R23C55 解题思路:
题目意思很简单,就是变换两种表达方式,题目很水。。 实现代码:
#include<bits/stdc++.h>
using namespace std; int main()
{
int m,i;
string s;
char s1[];
cin>>m;
while(m--){
cin>>s;
int num = ;
for(i=;i<s.size()-;i++){
if(s[i]<='Z'&&s[i]>='A'&&s[i+]>=''&&s[i+]<='')
num++;
}
if(num == ){
int r = ,c = ;
for(i=;i<s.size();i++){
if(s[i]>=''&&s[i]<=''){
r = r* + s[i] - '';
}
if(s[i]<='Z'&&s[i]>='A'){
c = c* + s[i] - 'A'+;
//cout<<"c"<<c<<endl;
}
}
cout<<"R"<<r<<"C"<<c<<endl;
}
else{
int flag = ,r = ;
for(i=;i<s.size();i++){
if(s[i]=='C') {flag = i;break;}
}
for(i=flag + ;i<s.size();i++){
r = r* + s[i] - '';
}
//cout<<"r"<<r<<endl;
int k =;
while(r){
if(r%==){ //特殊情况当s[i] = Z 的时候,%26 = 0,不符合式子,而且此时 r/26 必须减一,具体为什么自己带两个数据推下就知道。
s1[k++] = 'Z';
r=r/-;}
else{
s1[k++] = 'A' + r%-;
r/=;}
}
for(i=k-;i>=;i--)
cout<<s1[i];
for(i=;i<flag;i++)
cout<<s[i];
cout<<endl;
}
}
return ;
}