cf------(round)#1 B. Spreadsheets(模拟)

时间:2022-05-05
本文章向大家介绍cf------(round)#1 B. Spreadsheets(模拟),主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

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.

Sample test(s)

Input

2
R23C55
BC23

Output

BC23
R23C55

代码:
 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 using namespace std;
 5 int main()
 6 {
 7     int n,i;
 8     char str[20];
 9     bool flag;
10     //freopen("test.in","r",stdin);
11     //freopen("test.out","w",stdout);
12     scanf("%d",&n);
13         while(n--){
14            scanf("%s",str);
15            flag=true;
16            int len=strlen(str);
17            if(str[1]>='0'&&str[1]<='9'){
18                 for(i=2;i<len;i++){
19                   if(str[i]>='A'&&str[i]<='Z'){
20                     //说明是第二种格式r--c--
21                      char ss[10]="";
22                      strncpy(ss,str+1,i-1);
23                      //printf("%s%sn",str+i+1,ss);
24                      //先转化为整数
25                      int ans=0;
26                      int t=1;
27                      i++;
28                      while((len--)>i){
29                          ans+=((int)(str[len]-'0'))*t;
30                         t*=10;
31                      }
32                       i=0;
33                      int st[10]={0};
34                      while(ans>0){
35                             //temp=work(i);
36                        if(ans%26==0){
37                              if(ans>=26)st[i++]=26;
38                              else st[i++]=ans;
39                           ans/=26;
40                              ans--;
41                        }
42                     else{
43                          st[i++]=ans%26;
44                          ans/=26;
45                         }
46                      }
47                     for(--i;i>=0;i--){
48                     if(st[i]) putchar((st[i]-1+'A'));
49                     else putchar('Z');
50                  }
51                  printf("%sn",ss);
52                  flag=false;
53                  break;
54                 }
55               }
56            }
57            //第一种格式
58            if(flag) {
59              char ss[10]="";
60              int k=0;
61              for( i=0;i<len;i++){
62                    if(str[i]>='A'&&str[i]<='Z')
63                        ss[k++]=str[i];
64                 else break;
65                }
66                printf("R%sC",str+i);
67                int ans=0,t=1;
68                while(k--){
69                    ans+=((int)(ss[k]-'A')+1)*t;
70                    t*=26;
71                }
72                printf("%dn",ans);
73            }
74         }
75   return 0;
76 }