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.
【输入】
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 .
【输出】
Write n lines, each line should contain a cell coordinates in the other numeration system.
【样例输入】
2
R23C55
BC23
【样例输出】
BC23
R23C55
题目链接:http://codeforces.com/problemset/problem/1/B
代码如下:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
string s;
cin>>s;
int pos=0;
while(isalpha(s[pos])) pos++;
while(isdigit(s[pos]) && pos<s.size()) pos++;
if(pos==s.size())
{
int p=0,x=0,y=0;
while(isalpha(s[p])) y=26*y+s[p++]-'A'+1;
while(p<s.size()) x=10*x+s[p++]-'0';
cout<<"R"<<x<<"C"<<y<<endl;
}
else
{
int p=1,x=0,y=0;
while(isdigit(s[p])) x=x*10+s[p++]-'0';
p++;
while(p<s.size()) y=y*10+s[p++]-'0';
char ch[10];
int t=0;
while(y)
{
if(y%26==0)
{
ch[t++]='Z';
y-=26;
}
else ch[t++]=char(y%26+64);
y/=26;
}
for(int j=t-1;j>=0;j--)
cout<<ch[j];
cout<<x<<endl;
}
}
return 0;
}
下一篇: 使用nodejs进行前后端交互
推荐阅读
-
CodeForces - [ACM-ICPC Jiaozuo Onsite A]Xu Xiake in Henan Province(模拟)
-
Codeforces Round #533 (Div. 2) D. Kilani and the Game(bfs+模拟)
-
codeforces 1375D 模拟+思维
-
Codeforces Round #258 (Div. 2) B. Sort the Array (模拟)
-
Codeforces Round #256 (Div. 2) B. Suffix Structures(模拟)_html/css_WEB-ITnose
-
B. Nastya Is Playing Computer Games---(水题模拟)Codeforces Round #546 (Div. 2)
-
B. Two Arrays(模拟+思维)Codeforces Round #673 (Div. 2)
-
B. Disturbed People(模拟) Codeforces Round #521 (Div. 3)
-
D. Sequence and Swaps(模拟+枚举) Educational Codeforces Round 99 (Rated for Div. 2)
-
CodeForces - 1256B Minimize the Permutation(思维模拟)