Codeforces Beta Round #1 B. Spreadsheets 模拟
2016-03-06 22:12
246 查看
B. Spreadsheets
题目连接:
http://www.codeforces.com/contest/1/problem/BDescription
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 106Output
Write n lines, each line should contain a cell coordinates in the other numeration system.Sample Input
2R23C55
BC23
Sample Output
BC23R23C55
Hint
题意
表格有两种表示方法,第一种比如R23C55,就表示第23行,55列
第二种:
比如BC23,就表示在第BC列,23行,BC是一个26进制数,A是1,Z是26,BC就表示55=2*26+3
然后给你其中一种,让你转化成另外一种
题解:
模拟题,瞎跑跑就好了……简单模拟题,进制转换,直接看(这个数-1)%26就好了。
代码
#include<bits/stdc++.h> using namespace std; string s; void solve1() { int R=0,C=0; int flag = 0; for(int i=1;i<s.size();i++) { if(s[i]=='C')flag=1; if(s[i]=='C')continue; if(flag==0)R=R*10+(s[i]-'0'); else C=C*10+(s[i]-'0'); } string ans; while(C) { int p = (C-1)%26; C=(C-1)/26; ans+=(p+'A'); } reverse(ans.begin(),ans.end()); cout<<ans<<R<<endl; } void solve2() { int flag = 0; int C=0; for(int i=0;i<s.size();i++) { if(s[i]<='9'&&s[i]>='0'&&flag==0) { flag = 1; cout<<"R"; } if(flag==1)cout<<s[i]; else C=C*26+(s[i]-'A'+1); } cout<<"C"<<C<<endl; } int main() { int time; scanf("%d",&time); while(time--) { cin>>s; int flag1=0,flag2=0,flag3=0; for(int i=0;i<s.size();i++) { if(s[i]=='R')flag1++; if(s[i]=='C')flag2++; if(s[i]<='Z'&&s[i]>='A') flag3++; } if(s[0]=='R'&&s[1]=='C')flag1=0; if(flag3==2&&flag1&&flag2) solve1(); else solve2(); } }
相关文章推荐
- SSH批量部署服务
- XCode和Cocoa在开发中使用第三方dylib示例
- php接收上传文件
- Node建立HTTP服务器
- NodeJS和npm的安装,以及在安装express可能报错的解决办法
- Maven学习总结(二)—— eclipse中使用Maven创建Web项目
- 爬虫第一章笔记
- 1205 吃糖果
- [Programming WCF Services]Chapter 1. WCF Essentials - Metadata Exchange
- 斜面上的根骨骼运动以及刚体测试
- windows操作系统记事本保存操作时间、字符映射表的打开、步骤记录器使用
- java的环境变量和系统属性
- C语言全局变量和静态变量
- UVA 11090(p333)----Going in Cycle!!
- MVC、MVP、MVVM
- 《逻辑思维简易入门》(第2版) 阅读笔记二
- js控制html下拉框select的选择
- 深度学习框架大战正在进行,谁将夺取“深度学习工业标准”的荣耀?
- 无人值守自动安装linux系统
- ansible<1>