前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >cf------(round)#1 B. Spreadsheets(模拟)

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

作者头像
Gxjun
发布2018-03-22 14:18:27
5280
发布2018-03-22 14:18:27
举报
文章被收录于专栏:ml

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

代码语言:javascript
复制
2
R23C55
BC23

Output

代码语言:javascript
复制
BC23
R23C55

代码:
代码语言:javascript
复制
 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]="\0";
22                      strncpy(ss,str+1,i-1);
23                      //printf("%s%s\n",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("%s\n",ss);
52                  flag=false;
53                  break;
54                 }
55               }
56            }
57            //第一种格式
58            if(flag) {
59              char ss[10]="\0";
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("%d\n",ans);
73            }
74         }
75   return 0;
76 }
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2014-08-19 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档