CodeForces-1B(电子表格-模拟)

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
Copy
2
R23C55
BC23
output
Copy
BC23
R23C55


Excel是最常用的办公软件。每个单元格都有唯一的地址表示。比如:第12行第4列表示为:“D12”,第5行第255列表示为“IU5”。
事实上,Excel提供了两种地址表示方法,还有一种表示法叫做RC格式地址。
第12行第4列表示为:“R12C4”,第5行第255列表示为“R5C255”。
你的任务是:编写程序,实现从RC地址格式到常规地址格式的转换。
【输入、输出格式要求】
用户先输入一个整数n(n<100),表示接下来有n行输入数据。
接着输入的n行数据是RC格式的Excel单元格地址表示法。
程序则输出n行数据,每行是转换后的常规地址表示法。
例如:用户输入:
2
R12C4
R5C255
则程序应该输出:
D12
IU5

比如704代表AAB,以下为转换过程:
704%26=2-->B;
704/26=27;
27%26=1->A;
27/26=1;
1%26=1->A;
1/26=0;
此时c=0,结束循环
注意到如果涉及到Z,就有点不同了。
如果余0,代表Z,然后令c--才是正确结果,
比如702代表ZZ,转换过程如下:
702%26=0-->Z;
704/26=27;
27--;
26%26=0->Z;
26/26=1;
1--;
此时c=0,结束循环

这个题需要注意的其实就是   数字的转化%26的小细节,不像平时我们认为的满26进一。

#include<bits/stdc++.h>
using namespace std;
int judge(char a[]){
    int i;
    int len=strlen(a);
    if(a[0]=='R'){
        for(i=0;i<len;i++){
            if(isdigit(a[i])&&i>=1)
               continue;
            if(a[i]=='C'&&isdigit(a[i-1])&&isdigit(a[i+1]))
                return 1;
        }
    }
    return 0;
}
int main()
{
     int n,i,j;
     while(~scanf("%d",&n)){
        while(n--){
              int n1,n2;
              char a[200];
              int  b[200]={0};
              char c[200]={'\0'};
              scanf("%s",a);
              if(judge(a)){
                  sscanf(a,"R%dC%d",&n1,&n2);
                  i=0;
                  while(n2>0){
                      if(n2%26==0){
                         b[i++]=26;
                         n2--;
                      }else{
                         b[i++]=n2%26;
                      }
                      n2/=26;
                  }
                  for(i--;i>=0;i--){
                     printf("%c",b[i]+64);
                  }
                  printf("%d\n",n1);
              }
              else{
                  sscanf(a,"%[A-Z]%d",c,&n2);          //sscanf(a,%[A-Z],c);把大写的字母都吸收
                  int len=strlen(c);
                  reverse(c,c+len);
                  n1=0;
                  for(i=0;i<strlen(c);i++){
                      n1+=((c[i]-'A'+1)*pow(26,i));
                  }
                  printf("R%dC%d\n",n2,n1);
              }
        }
     }
     return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值