Codeforces 1B Spreadsheets
2017-04-30 11:12
399 查看
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
题意
给定一个字符串,分别代表着行和列,并且有二种表达方式,一种是RXCY,其中X为行,Y为列,都为整型
第二种是一段字符跟着一个数字。
题目让你将这二种表达方式进行互换,即给第一种就返回第二种,给第二种即返回第三种。
本题重点在于字符串提取,直接用是sscanf即可。
代码
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
题意
给定一个字符串,分别代表着行和列,并且有二种表达方式,一种是RXCY,其中X为行,Y为列,都为整型
第二种是一段字符跟着一个数字。
题目让你将这二种表达方式进行互换,即给第一种就返回第二种,给第二种即返回第三种。
本题重点在于字符串提取,直接用是sscanf即可。
代码
#include<cstdio> #include<iostream> #include<cstring> #include<cmath> using namespace std; char str[1024], tempStr[1024]; int row, column; void printcol(int c) { if(!c) { return; } printcol((c - 1) / 26); putchar(((c - 1) % 26) + 'A'); } int main() { int n,i; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%s", str); if(sscanf(str,"R%dC%d", &row, &column) == 2) { printcol(column); printf("%d\n", row); } else { sscanf(str, "%[A-Z]%d", tempStr, &row); int j = 0; column = 0; while(tempStr[j] != '\0') { column *= 26; column += tempStr[j] - 'A' + 1; j++; } printf("R%dC%d\n", row, column); } } return 0; }
相关文章推荐
- codeforces 1B Spreadsheets
- CodeForces 1B Spreadsheets
- Codeforces 494A
- CodeForces 651A-Joysticks
- codeforces 706 B
- CodeForces 586A
- CodeForces - 663A
- codeforces Towers 题解
- CodeForces - 518A Vitaly and Strings(水题)
- codeforces 651B B. Beautiful Paintings
- Codeforces 598A Tricky Sum【计数】
- CodeForces - 725A
- codeforces 523D tatistics of Recompressing Videos
- Codeforces 938.B Run For Your Prize
- CodeForces 514D.R2D2 and Droid Army (线段树+双指针)
- codeforces Good Bye 2015 C - New Year and Domino
- codeforces 707 B. Bakery【图论】
- Codeforces 682D Alyona and Strings【dp】
- CodeForces 840E. In a Trap
- [几何 平面图欧拉定理] Codeforces 933C. A Colourful Prospect