Problem:
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 ≤ 10^5), 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 10^6 .
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进制转化
#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)//如果形式为RXCY
{
ll r = 0, c = 0;
for (ll i = 1; i < k2; i++)
{
r = r * 10 + (s[i] - '0');//读取相应X
}
for (ll i = k2 + 1; i < s.length(); i++)
{
c = c * 10 + (s[i] - '0');//读取相应Y
}
ll k = 0;
while (c)//进制转化 将Y转化成26进制下的数字
{
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 rr = 0;
for (ll i = 0; i < k3; i++)//获取26进制下的字母
{
u[i] = s[i];
}
ll cc = 0;
for (ll i = 0; i < k3; i++)
{
cc = cc * 26 + u[i] - 'A' + 1;//将26进制转化为10进制
}
for (ll i = k3; i < s.length(); i++)
{
rr = rr * 10 + (s[i] - '0');
}
cout << "R" << rr << "C" << cc << endl;
}
}
return 0;
}