1B. Spreadsheets【进制转换】
2016-06-09 10:54
495 查看
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
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.
Examples
input
2 R23C55 BC23
output
BC23 R23C55
进制转换是关键,一个简单的进制转换卡了一上午,真心感觉弱爆了.....
/* http://blog.csdn.net/liuke19950717 */ #include<cstdio> #include<cmath> #include<cstring> #include<stack> using namespace std; typedef long long ll; const int maxn=1005; bool judge(char s[])//判断是否是声明行和列的方式 { int len=strlen(s); if(len<=2) { return 0;//没有声明行和列 } int kase=0; for(int i=0;i<len;++i) { if(s[i]>='A'&&s[i]<='Z'&&kase) { return 1; } if(s[i]>='0'&&s[i]<='9') { kase=1; } } return 0; } void slove(char s[]) { int len=strlen(s); if(judge(s))//声明了行和列 { int x=0,y=0,i=1; while(s[i]!='C') { y=y*10+s[i]-'0'; ++i; } ++i; while(i<len) { x=x*10+s[i]-'0'; ++i; } stack<char> ans; while(x) { int tp=(x-1)%26+'A'; ans.push(tp); x=(x-1)/26; } while(!ans.empty()) { printf("%c",ans.top()); ans.pop(); } printf("%d",y); } else { int x=0,y=0,i=0; while(s[i]>='A'&&s[i]<='Z') { y=y*26+s[i]-'A'+1; ++i; } while(i<len) { x=x*10+s[i]-'0'; ++i; } printf("R%dC%d",x,y); } printf("\n"); } int main() { int t; scanf("%d",&t); while(t--) { char s[maxn]={0}; scanf("%s",s); slove(s); } return 0; }
相关文章推荐
- actionbar以及制定
- 搭建Nginx与tomcat整合,用Nginx代替apache
- Linux环境下字符设备驱动开发入门
- actionbar setDisplayOptions用法详解
- Mysql优化方案二之数据库类型选择及Sql语句优化
- 浅谈HashMap与HashTable
- GBK 编码
- Python函数
- CentOS下安装Nginx
- python使用网易云音乐 api下载mv
- BZOJ 1072: [SCOI2007]排列perm
- 机器学习文章
- asp.net提取多层嵌套json数据的方法
- 内装式模块
- 6框架、文档和窗口
- django 2
- 元素过滤器(Element Filters)
- 51nod 1266 蚂蚁
- 学习MongoDB 十一: MongoDB聚合(Aggregation Pipeline基础篇上)(三)
- Python学习 (爬豆瓣电影)