codeforces 1B Spreadsheets
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.
Example
2
R23C55
BC23
BC23
R23C55
解题思路:
题目意思很简单,就是变换两种表达方式,题目很水。。
实现代码:
#include<bits/stdc++.h> using namespace std; int main() { int m,i; string s; char s1[1000009]; cin>>m; while(m--){ cin>>s; int num = 0; for(i=0;i<s.size()-1;i++){ if(s[i]<='Z'&&s[i]>='A'&&s[i+1]>='0'&&s[i+1]<='9') num++; } if(num == 1){ int r = 0,c = 0; for(i=0;i<s.size();i++){ if(s[i]>='0'&&s[i]<='9'){ r = r*10 + s[i] - '0'; } if(s[i]<='Z'&&s[i]>='A'){ c = c*26 + s[i] - 'A'+1; //cout<<"c"<<c<<endl; } } cout<<"R"<<r<<"C"<<c<<endl; } else{ int flag = 1,r = 0; for(i=1;i<s.size();i++){ if(s[i]=='C') {flag = i;break;} } for(i=flag + 1;i<s.size();i++){ r = r*10 + s[i] - '0'; } //cout<<"r"<<r<<endl; int k =0; while(r){ if(r%26==0){ //特殊情况当s[i] = Z 的时候,%26 = 0,不符合式子,而且此时 r/26 必须减一,具体为什么自己带两个数据推下就知道。 s1[k++] = 'Z'; r=r/26-1;} else{ s1[k++] = 'A' + r%26-1; r/=26;} } for(i=k-1;i>=0;i--) cout<<s1[i]; for(i=1;i<flag;i++) cout<<s[i]; cout<<endl; } } return 0; }