codeforces--Spreadsheets(模拟)
来源:互联网 发布:oracle数据库安装 编辑:程序博客网 时间:2024/06/05 14:42
Description
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 Input
Input
2
R23C55
BC23
Output
BC23
R23C55
思路:
此题如果单纯地用普通进制数来想的话,那就大错特错了。因为比如:
26进制其位上的数字对应为0-25,而此题为1-26;也就是说没有0!!!
那么当计算时需要向前进位时,应当减去其低一位的能够存储的最大值。
就像52,对于普通26进制其结果应当为20,而此题为1 26!!!也就是进位的时候,向前进的实际值为总值减去低位能够存储的最大值!!!每一位都是要记录大于零的值!!!(没有错,我错了很多遍~~~)
#include <cstdio>#include <cstring>#include <set>#include <queue>#include <map>#include <iostream>#include <string>#include <algorithm>#include <vector>#include <cstdlib>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<<"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'; } int k =0; while(r) { if(r%26==0)//特判!!! { 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;}
- codeforces--Spreadsheets(模拟)
- codeforces--Spreadsheets(模拟)
- CodeForces 1B. Spreadsheets(模拟)
- CodeForces 1B Spreadsheets(模拟)
- Codeforces 1B Spreadsheets(模拟+26进制思想)
- Codeforces Spreadsheets
- 【codeforces 1B】Spreadsheets——模拟,水
- CodeForces 1B Spreadsheets(EXCEL)
- CODEFORCES:1B. Spreadsheets
- CodeForces 1B Spreadsheets
- CodeForces - 1B Spreadsheets
- Codeforces 1B. Spreadsheets
- codeforces-1B. Spreadsheets
- CodeForces 1B Spreadsheets
- CodeForces#1B Spreadsheets
- Codeforces #1 B. Spreadsheets
- CodeForces 1B Spreadsheets
- codeforces 1B Spreadsheets
- ART深入浅出2 -- 认识和了解Runtime Options
- 在ROS Kinetic中使用Gazebo 8进行机器人仿真
- 关于长单链表中间节点删除
- 负载均衡详解
- 【转】背包九讲 好好学!
- codeforces--Spreadsheets(模拟)
- STL: Map 的操作
- 二叉树的递归遍历
- Codeforces 282C XOR and OR【思维】
- Coursera解决无法播放视频问题
- Android—广播(Broadcast)—广播的注意事项及相关问题分析
- EA&UML日拱一卒-活动图::CallOperationAction(续)
- 【NOIP2016提高A组模拟7.21】Clock Sequence
- 梯度提升树GBDT原理