CodeForces 1B Spreadsheets
2016-02-12 23:31
239 查看
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
Output
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#include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn = 117; typedef __int64 LL; int is_letter(char c){ if(c >= 'A' && c <= 'Z') return 1; return 0; } int is_num(char c){ if(c >='0' && c <='9') return 1; return 0; } int main(){ LL t; char s[maxn]; scanf("%I64d",&t); getchar(); while(t--){ gets(s); int len = strlen(s); int k = 0; for(int i = 0; i < len; i++){ if(is_letter(s[i]) && is_num(s[i+1])){ k++; } } if(k == 2){ //R23C55形式 LL i, j; LL t1 = 0, t2 = 0; for(i = 1; ; i++){ if(is_num(s[i])) t1 = t1*10+s[i]-'0'; else break; } for(j = i+1; j < len; j++){ if(is_num(s[j])) t2 = t2*10+s[j]-'0'; else break; } //printf("t1::%I64d t2::%I64d\n",t1,t2); char a[maxn]; i = 0; while(t2){ LL tt = t2%26; a[i++] = tt+'A'-1; t2/=26; if(tt == 0){ //注意 t2--; a[i-1] = 'Z'; } } for(j = i-1; j >= 0; j--){ printf("%c",a[j]); } printf("%I64d\n",t1); } else{ //BC23形式 LL i, j; LL t3 = 0, t4 = 0; for(i = 0; ; i++){ if(is_num(s[i])) break; t3 = t3*26+(s[i]-'A'+1); } for(j = i; j < len; j++){ t4 = t4*10+s[j]-'0'; } printf("R%I64dC%I64d\n",t4,t3); } } return 0; }
相关文章推荐
- 供给侧也好,需求侧也好,都只是个名词
- git使用心得
- 一步步解析Python斗牛游戏的概率
- 使用FloatingActionButton无法浮现在ListView的原因
- JavaWeb_Session实现简易购物车
- Swift学习笔记之UIButton(一)
- 39度发烧堂:常用音频格式有什么区别?
- 华为机试题: 整型数排序(JAVA)
- Masonry介绍与使用实践:快速上手Autolayout
- GCD线程的应用
- android 的文件存储
- JavaWeb_相对路径与绝对路径
- JavaWeb_Session讲解
- 李彦宏:百度的成功和谷歌退出没有必然联系
- 李彦宏:百度的成功和谷歌退出没有必然联系
- hdu1114 Piggy-Bank(完全背包)
- js三元运算符 js运算符优先级
- java学习--常量池
- Curator框架
- 在腾讯的第一堂产品课——菜鸟产品经理还是有专业度的产品经理------文章整理