###### 雪的期许

.

time limit per test
10 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output

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

1、RxCy 型，表示第x行第y列

2、**x型，（*代表任意大写字母）表示第x行，第**列。

#include<stdio.h>
#include<string.h>
typedef long long ll;
char s[1000100];
void zhuan(ll x)
{
if(x==0)
return;
if(x%26==0)
x-=26;//由于26进制不进位，下一位的进制转换之前，先减掉
zhuan(x/26);
int temp=x%26+'A'-1;
if(temp<'A')
temp='Z';//x==26时，x%26==0，特殊情况
printf("%C",temp);
}
void R(char s[])
{
int len=strlen(s);
ll x=0,y=0;
int count=0;
for(int i=0;i<len;i++)
{
if(s[i]>='0'&&s[i]<='9')
{
count++;
if(count==1)
{
while(s[i]>='0'&&s[i]<='9')
x=x*10+s[i++]-'0';
i--;
}
else
{
while(s[i]>='0'&&s[i]<='9')
y=y*10+s[i++]-'0';
i--;
}
}
}
//进制转换
zhuan(y);
printf("%lld\n",x);
}
void A(char s[])
{
int len=strlen(s);
ll x=0,y=0;
for(int i=0;i<len;i++)
{
while(s[i]>='A'&&s[i]<='Z')
{
x=x*26+s[i]-'A'+1;
i++;
}
while(s[i]<='9'&&s[i]>='0')
{
y=y*10+s[i]-'0';
i++;
}
}
printf("R%lldC%lld\n",y,x);
}
int main()
{
int n;
scanf("%d",&n);
while(n--)
{
scanf("%s",s);
int len=strlen(s);
int count=0;
for(int i=0;i<len;i++)
{
if(s[i]>='0'&&s[i]<='9')
{
count++;
while(s[i]>='0'&&s[i]<='9')i++;
i--;
}
}
if(count>1)
R(s);
else
A(s);
}
return 0;
}

2014-07-22 09:41:10

2016-07-21 16:17:12

2015-06-04 22:47:59

2014-05-01 16:55:53

2016-03-20 23:16:06

2006-10-11 13:34:00

2017-06-26 21:51:20

2006-11-03 16:27:00

#### 【机房重构】如何将Excel表格导出到WPS

2016-03-27 20:43:42

#### 【优化】Codeforces Beta Round #1 / 1B Spreadsheets (字符串处理)

2013-08-18 11:06:34