codeforces 01B
阅读原文时间:2023年07月08日阅读:1

B. Spreadsheets

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

这题唯一麻烦的一点,就是如果把CXX转化为字母,由题意我们可以知道,A是1,但我们操作的时候,一般都是某个数字+‘A'的ascii码
例如:
  y=x+'A';
这个时候,y如果是’A‘,那么x就是0了,但按照题意,x为1,y才等于'A',所以应该将x减一
知道这点,这题就好做了

附本人ac代码(很多地方都写的很麻烦):

1 #include
2 #include
3 #include
4 #include
5 using namespace std;
6 bool dig(char u) {
7 if(u >= '0' && u <= '9') return true; 8 return false; 9 } 10 int main() { 11 ios::sync_with_stdio(false); 12 int n,flag = 0; 13 14 cin>>n;
15 while(n--) {
16 string a;
17 string rr,cc;
18 flag = 0;
19 cin>>a;
20 for(int i = 0; i < a.length()-1; i++) { 21 if(dig(a[i]) && !dig(a[i+1])){ 22 flag = 1; 23 break; 24 } 25 } 26 27 // cout<= 0; i--) {
49 cout<<cc[i];
50 }
51 cout<<r<<endl;
52 }
53 else {
54 int len = 0;
55 int c = 0,r = 0;
56 while(!dig(a[len])) {
57 c = c*26 + a[len] - 'A' + 1;
58 len++;
59 }
60 while(len < a.length()) {
61 r = r*10 + a[len] - '0';
62 len++;
63 // cout<<r<<" "<<a[len]<<endl;
64 }
65 cout<<"R"<<r<<"C"<<c<<endl;
66 }
67 }
68 return 0;
69 }

附高手代码:

1 #include
2 void g(int t){if(t){g((t-1)/26);putchar(65+(t-1)%26);}}
3 int main(){
4 int n,x,y;
5 char s[64],*p;
6 for(scanf("%d ",&n);n--;){
7 gets(s);
8 if(sscanf(s,"%*c%d%*c%d",&x,&y)==2){
9 g(y);
10 printf("%d\n",x);
11 }else{
12 for(x=0,p=s;*p>64;++p)
13 x=x*26+*p-64;
14 printf("R%sC%d\n",p,x);
15 }
16 }
17 return 0;
18 }

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器