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.
Examples
Input
2
R23C55
BC23
Output
BC23
R23C55
题意:转化excel表格(26进制转化)
就举样例给的栗子吧:
R23C55 表示23行55列 把23行55列坐标写出来
BC23 表示一个坐标是BC23 写出他的多少行多少列
题解:注意3点就很简单了
1.输入怎么判断是哪种形式 判断第一种就行了 输入一个string
判断 s[0]= =‘R’ && s[1]<=‘9’ && s[1]>=‘0’ && k2>=2 && k1= =0
2.十进制转26进制
因为A 和 Z对26取余都是0 所以让(sum-1)%26+‘A’ 然后sum/=(sum-1)/26 循环就行了
3.26进制转10进制 :
w=w26+u[i]-‘A’+1;(w初始值为0)
这样好像不理解,大家可以模拟下10进制,
345
1. ans=0 ans=ans10+3=3;
2. ans=3 ans=ans10+4=34;
3. ans=34 ans=ans10+5=345;
解决这些问题就很简单了
AC代码:
#include<iostream>
#include<cmath>
typedef long long ll;
using namespace std;
char p[26];
int main()
{
ll t;
cin>>t;
while(t--)
{
string s;
cin>>s;
ll k1=-1,k2=-1;
for(ll i=0;i<s.length();i++)
{
if(s[i]=='R')
k1=i;
else if(s[i]=='C')
k2=i;
}
if(s[0]=='R'&&s[1]<='9'&&s[1]>='0'&&k2>=2&&k1==0)
{
ll r=0,c=0;
for(ll i=1;i<k2;i++)
{
r=r*10+(s[i]-'0');
}
for(ll i=k2+1;i<s.length();i++)
{
c=c*10+(s[i]-'0');
}
// cout<<r<<" "<<c<<endl;
ll k=0;
while(c)
{
p[k++]=(c-1)%26+'A';
c=(c-1)/26;
}
for(ll i=k-1;i>=0;i--)
cout<<p[i];
cout<<r<<endl;
}
else
{
char u[26];
ll k3;
for(ll i=0;i<s.length();i++)
{
if(s[i]<='Z'&&s[i]>='A')
continue;
else
{
k3=i;
break;
}
}
ll o=0;
for(ll i=0;i<k3;i++)
{
u[i]=s[i];
}
ll w=0;
// for(int i=0;i<k3;i++)
// {
// cout<<u[i]<<" ";
// }
// cout<<endl;
for(ll i=0;i<k3;i++)
{
w=w*26+u[i]-'A'+1;
}
for(ll i=k3;i<s.length();i++)
{
o=o*10+(s[i]-'0');
}
// cout<<o<<endl;
cout<<"R"<<o<<"C"<<w<<endl;
}
}
return 0;
}