cf------(round)#1 B. Spreadsheets(模拟)
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
2
R23C55
BC23
Output
BC23
R23C55
代码:
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]=" ";
22 strncpy(ss,str+1,i-1);
23 //printf("%s%sn",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("%sn",ss);
52 flag=false;
53 break;
54 }
55 }
56 }
57 //第一种格式
58 if(flag) {
59 char ss[10]=" ";
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("%dn",ans);
73 }
74 }
75 return 0;
76 }
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- CentOS 7更新时出现:Multilib version problems问题的解决方法
- Linux模拟网络丢包与延迟的方法
- centos6.5通过yum安装nginx
- Linux系统利用cp命令实现强制覆盖功能的方法
- leetcode队列之设计循环双端队列
- Centos7学习之添加用户和用户组的方法
- Linux静态库与动态库实例详解
- Linux字符终端如何用鼠标移动一个红色矩形详解
- Linux中出现“No space left on device”错误的排查与解决方法
- 浏览器是如何调度进程和线程的?
- Linux shell利用sed如何批量更改文件名详解
- linux下通过xinetd服务管理 rsync 实现开机自启动
- linux实现自动删除最旧的几个文件详解
- 基于Ubuntu 16.04设置固定IP的方法教程
- CentOS添加和删除用户以及用户组的方法