1B. Spreadsheets
2015-11-23 16:25
387 查看
1B. 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.
import string import re def RCPattern(s): rc='R(\d+)C(\d)' m=re.match(rc,s) if m is not None: RCtoAnother(s) else: AnothertoRC(s) def RCtoAnother(s): TheEnd=s.find('C') second=s[1:TheEnd] first=s[TheEnd+1:] first=string.atoi(first) result='' while first>0: digit=(first-1)%26 result+=chr(ord('A')+digit) first=(first-digit)//26 result=result[::-1]+second print result def AnothertoRC(s): num=0 for i in range(len(s)): num=i if s[i] in string.digits: break first=s[:num] second=s[num:] result='R'+second+'C' somelse=0 for i in first: somelse*=26 somelse+=1+ord(i)-ord('A') result=result+str(somelse) print result if __name__=='__main__': num=raw_input() num=string.atoi(num) InputList=[] for i in range(num): quest=raw_input() InputList.append(quest) for i in range(len(InputList)): RCPattern(InputList[i])
Sample test(s)
input
2 R23C55 BC23
output
BC23 R23C55
相关文章推荐
- android studio 改变主题及字体大小
- 第十二周 项目四(5) 利用遍历思想求解图问题
- MySQL 基本查询语法使用
- redhat 6 改yum数据源
- 关于PCA主成分分析与KL变换
- 1、DHCP配置实验
- CentOS安装 EPEL yum源方法
- mysql limit
- 虚拟操作栏
- protobuf简介和使用
- 如果Java 失宠于Oracle,那么未来会怎么样?
- 关于cocoaPods 创建和一些解决问题
- LeetCode Swap Nodes in Pairs
- ExecutorService的任务调度
- struts的excute方法
- 第十二周项目4--利用遍历思想求解图问题
- 第十二周 项目4 利用遍历思想求解图问题(输出简单路径 )
- 第十一周-二叉树的构造
- 为什么寄存器比内存快?
- uva 725