Codeforces Beta Round #1 B. Spreadsheets 模拟
B. Spreadsheets
题目连接:
http://www.codeforces.com/contest/1/problem/B
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
2
R23C55
BC23
Sample Output
BC23
R23C55
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();
}
}
Codeforces Beta Round #1 B. Spreadsheets 模拟的更多相关文章
- Codeforces Beta Round #3 C. Tic-tac-toe 模拟题
C. Tic-tac-toe 题目连接: http://www.codeforces.com/contest/3/problem/C Description Certainly, everyone i ...
- Codeforces Beta Round #5 B. Center Alignment 模拟题
B. Center Alignment 题目连接: http://www.codeforces.com/contest/5/problem/B Description Almost every tex ...
- Codeforces Beta Round #77 (Div. 2 Only)
Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...
- Codeforces Beta Round #75 (Div. 2 Only)
Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...
- Codeforces Beta Round #74 (Div. 2 Only)
Codeforces Beta Round #74 (Div. 2 Only) http://codeforces.com/contest/90 A #include<iostream> ...
- Codeforces Beta Round #73 (Div. 2 Only)
Codeforces Beta Round #73 (Div. 2 Only) http://codeforces.com/contest/88 A 模拟 #include<bits/stdc+ ...
- Codeforces Beta Round #72 (Div. 2 Only)
Codeforces Beta Round #72 (Div. 2 Only) http://codeforces.com/contest/84 A #include<bits/stdc++.h ...
- Codeforces Beta Round #67 (Div. 2)
Codeforces Beta Round #67 (Div. 2) http://codeforces.com/contest/75 A #include<bits/stdc++.h> ...
- Codeforces Beta Round #65 (Div. 2)
Codeforces Beta Round #65 (Div. 2) http://codeforces.com/contest/71 A #include<bits/stdc++.h> ...
随机推荐
- device tree 負值 property 寫法
倘若你要設定 負值的property, 可能需要括符才會 build 過. 正確 decidegc = <(-10)>; 錯誤 decidegc = <-10>;
- linux内核启动分析(2)
-----以下内容为从网络上整理所得------ 主要介绍kernel_init线程(函数),这个线程在rest_init函数中被创建,kernel_init函数将完成设备驱动程序的初始化,并调用in ...
- Makefile系列之二 : 命令
一.显示命令 echo “@”字符可以控制命令是否在屏幕上显示,如 @echo 正在编译XXX模块...... 输出: 正在编译XXX模块...... 如果没有“@"则输出 : echo ...
- Vim常用命令(转)—默写版
1.光标移动 上: 下: 左: 『字母小写』 右: 上一行行首: 『减号』 下一行行首: 行首: 『数字0』 行尾: 单词词尾或后一个单词词尾: 后一个单词词首: 单词词首或前一个单词词首: 跳转到特 ...
- 《逐梦旅程 WINDOWS游戏编程之从零开始》笔记9——游戏摄像机&三维地形的构建
第21章 游戏摄像机的构建 之前的程序示例,都是通过封装的DirectInput类来处理键盘和鼠标的输入,对应地改变我们人物模型的世界矩阵来达到移动物体,改变观察点的效果.其实我们的观察方向乃至观察点 ...
- CentOS7.5安装坚果云
1.下载坚果云rpm包,对于CentOS,选fedora那个版本的包 https://www.jianguoyun.com/s/downloads/linux 2.安装 坚果云安装依赖notify-p ...
- 关于Vue-cli的跨域解决
由于Vue-cli服务器是跑在node环境下的8080端口,我们的php代码可能在Apache环境下的7070端口,这个时候就会出现跨域 此刻这段php代码在7070端口上 如果直接去访问 页面报错 ...
- spark sql遇到的问题
项目背景:计算平台架构hadoop spark spark on yarn,支持多种sql引擎如hive.spark sql.impala等. 问题描述:SPARK SQL在做insert ove ...
- Bzoj3942 Censoring(KMP)
\(KMP\)问题的核心在于数组\(next\)(或者\(pre\)/\(fail\),各种叫法),几乎所有的此类型题都是需要计算\(next\)的. 这里解释一波\(next\):即满足字符子串\( ...
- NGUI 简单的背包系统
1.首先在场景中创建格子,用来存放物体的 2.为每一个格子设置标签为Item,建议只做一个格子,然后创建预制体就可以了,然后为每一个格子附加Box Collider组件,要用于检测嘛, 3.接下来就是 ...