B. Spreadsheets
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.
这题只有俩个情况一个是 字符+数字 另一个是 字符+数字+字符+数字 只要判断他是哪一种,然后进制转换就可以了,把第一类转成第二类,第二类转成第一类
代码如下:
#include "bits/stdc++.h"
using namespace std;
string str="ABCDEFGHIJKLMNOPQRSTUVWXYZ";//用于进制转换
int main(){
int x;
string s;
cin>>x;
while (x--){
cin>>s;
int cs=0;
for(int i=1;i<s.size();i++)if(s[i]>='0'&&s[i]<='9'&&s[i-1]>='A'&&s[i-1]<='Z')cs++; //记录数字在字母后面的又几次,来判断是哪一类
if(cs==1){//字母+数字 类
int ans=0,zhi=0;
string s1;
for(int i=0;i<s.size();i++){
if(s[i]>='A'&&s[i]<='Z'){
s1+=s[i];
} else{
zhi=zhi*10+(s[i]-'0');
}
}
for (int i = 0; i < s1.size(); i++)ans+=((s[i]-'A'+1)*pow(26,s1.size()-i-1));//转10进制
cout<<"R"<<zhi<<"C"<<ans<<endl;
}else{
string zhi="",ans="";
int ans1=0,flag=1;
for(int i=0;i<s.size();i++){
if(s[i]>='0'&&s[i]<='9'){
if(flag)zhi+=s[i];
else ans1=ans1*10+(s[i]-'0');
}else{
if(zhi.size())flag=0;
}
}
while (ans1){//转字母
int wz=((ans1%26-1)+26)%26;
ans.insert(ans.begin(),str[wz]);//把东西丢到字符串前端
if(ans1%26==0)ans1-=26;
ans1/=26;
}
cout<<ans<<zhi<<endl;
}
}
return 0;
}