codeforces——B. Spreadsheets
2014-10-26 21:33
330 查看
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 <map> #include <set> #include <list> #include <stack> #include <vector> #include <queue> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; char str[105]; char RC[105]; __int64 pow(int a, int b) { __int64 c = 1; while(b) { if (b & 1) { c *= a; } b >>= 1; a *= a; } return c; } int main() { int n; scanf("%d", &n); while (n--) { int cnt = 0; scanf("%s", str); int len = strlen(str); for (int i = 1; i < len; i++) { if ((str[i] >= '0' && str[i] <= '9') && (str[i - 1] >= 'A' && str[i] <= 'Z')) { cnt++; } } if (cnt >= 2) { __int64 r = 0; int i = 1; while (str[i] != 'C') { r = r * 10 + str[i] - '0'; i++; } __int64 c = 0, cnt = 0; i++; while (str[i] != '\0') { c = c * 10 + str[i] - '0'; i++; } i = 0; while (c) { if (c % 26 == 0) { RC[i] = 'Z'; c /= 26; c--; } else { RC[i] = 'A' + (c % 26) - 1; c /= 26; } i++; } while(i >= 1) { printf("%c", RC[i - 1]); i--; } printf("%I64d\n", r); continue; } int i = 0; while (str[i] >= 'A' && str[i] <= 'Z') { RC[i] = str[i]; i++; } __int64 r = 0; for (int j = 0; j < i; j++) { r += pow(26, i - j - 1) * (RC[j] - 'A' + 1); } printf("R"); for (; str[i] != '\0'; i++) { printf("%c", str[i]); } printf("C%I64d\n", r); } return 0; }
相关文章推荐
- codeforces B. Spreadsheets 计算excel的行列
- Codeforces Spreadsheets
- Codeforces Beta Round #1 B Spreadsheets
- codeforces B Spreadsheets
- Codeforces Round #401 (Div. 2) C. Alyona and Spreadsheet(暴力)
- Codeforces #401 (Div. 2) C. Alyona and Spreadsheet ( XJBX
- BW--ABAP code using BAPI's to load data into Cube from SpreadSheets
- Codeforces Beta Round #1 A - Theatre Square
- Educational Codeforces Round 13 A Johny Likes Numbers(水题)
- Subsequences CodeForces - 597C 树状数组 + dp
- Codeforces Round #466 (Div. 2)
- Codeforces Round #430 (Div. 2)
- Codeforces Round #465 (Div. 2)E. Fafa and Ancient Mathematics(CF935E)(树形动规)
- Codeforces Round #430(Div.2)Problem C Ilya And The Tree(DFS)
- Codeforces Gym 101612 | 2017-2018 NEERC St Petersburg Subregional
- Codeforces Round #248 (Div. 2)
- 【Codeforces Round 331 (Div 2)B】【水题 贪心】Wilbur and Array 修改对p位置后的所有位置生效 最少修改次数使得数列变成b
- Codeforces Round #360 (Div. 2)
- Codeforces Round #384 B. Chloe and the sequence
- Codeforces Round #430 D. Vitya and Strange Lesson