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 <cstdio>
2 #include <cstring>
3 #include <iostream>
4 #include <string>
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<<flag<<endl;
28 if(flag) { //rxcx
29 int r = 0,c = 0;
30 int len = 1;
31 while(dig(a[len])) {
32 r = r*10 + a[len] - '0';
33 // cout<<a[len]-'0'<<" "<<r<<endl;
34 len++;
35 }
36 len++;
37 while(len < a.length()) {
38 c = c*10 + a[len] - '0';
39 len++;
40 }
41 // cout<<c<<endl;
42 while(c) {
43 c--; //就是这里,注意减一
44 cc += c%26 + 'A';
45 c = c/26;
46 // cout<<c<<endl;
47 }
48 for(int i = cc.length() - 1; i >= 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<cstdio>
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 }


codeforces 01B的更多相关文章

  1. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  2. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  3. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  4. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  5. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  6. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  7. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

  8. CodeForces - 696B Puzzles

    http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...

  9. CodeForces - 148D Bag of mice

    http://codeforces.com/problemset/problem/148/D 题目大意: 原来袋子里有w只白鼠和b只黑鼠 龙和王妃轮流从袋子里抓老鼠.谁先抓到白色老鼠谁就赢. 王妃每次 ...

随机推荐

  1. [Usaco 2012 Feb]Nearby Cows

    题目描述 FJ发现他的牛经常跑到附近的草地去吃草,FJ准备给每个草地种足够的草供这个草地以及附近草地的奶牛来吃.FJ有N个草地(1<=N<=100000),有N-1条双向道路连接这些草地, ...

  2. [Usaco2005 Dec]Scales 天平

    题目描述 约翰有一架用来称牛的体重的天平.与之配套的是N(1≤N≤1000)个已知质量的砝码(所有砝码质量的数值都在31位二进制内).每次称牛时,他都把某头奶牛安置在天平的某一边,然后往天平另一边加砝 ...

  3. Spring Security 实战干货:AuthenticationManager的初始化细节

    1. 前言 今天有个同学告诉我,在Security Learning项目的day11分支中出现了一个问题,验证码登录和其它登录不兼容了,出现了No Provider异常.还有这事?我赶紧跑了一遍还真是 ...

  4. java.io.IOException: Could not find resource com/xxx/xxxMapper.xml

    java.io.IOException: Could not find resource com/xxx/xxxMapper.xml 报错内容: org.apache.ibatis.exception ...

  5. elasticsearch从开始到永久

    0.学习目标 独立安装Elasticsearch 会使用Rest的API操作索引 会使用Rest的API查询数据 会使用Rest的API聚合数据 掌握Spring Data Elasticsearch ...

  6.  打开APP  04 | 网络通信:RPC框架在网络通信上更倾向于哪种网络IO模型? 2020-02-26 何小锋

     打开APP  04 | 网络通信:RPC框架在网络通信上更倾向于哪种网络IO模型? 2020-02-26 何小锋

  7. LOJ10064黑暗城堡

    题目描述你知道黑暗城堡有 N 个房间,M 条可以制造的双向通道,以及每条通道的长度. 城堡是树形的并且满足下面的条件: 设 Di​ 为如果所有的通道都被修建,第 i 号房间与第 1 号房间的最短路径长 ...

  8. 精通MySQL之索引篇,这篇注重练习!

    老刘是即将找工作的研究生,自学大数据开发,一路走来,感慨颇深,网上大数据的资料良莠不齐,于是想写一份详细的大数据开发指南.这份指南把大数据的[基础知识][框架分析][源码理解]都用自己的话描述出来,让 ...

  9. docker基本使用-安装

    一. Linux服务器安装 1. 可参考官网安装步骤,点击前往官网 2. 常见问题 a. 在执行安装docker-ce命令的时候出错:requires containerd.io >= 1.2. ...

  10. ScalikeJDBC,操作mysql数据,API

    ScalikeJDBC,操作mysql数据,API 一.构建maven项目,添加pom.xml依赖 二.resource文件下创建application.conf文件,并配置以下内容 三.操作mysq ...