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 模拟的更多相关文章

  1. Codeforces Beta Round #3 C. Tic-tac-toe 模拟题

    C. Tic-tac-toe 题目连接: http://www.codeforces.com/contest/3/problem/C Description Certainly, everyone i ...

  2. Codeforces Beta Round #5 B. Center Alignment 模拟题

    B. Center Alignment 题目连接: http://www.codeforces.com/contest/5/problem/B Description Almost every tex ...

  3. Codeforces Beta Round #77 (Div. 2 Only)

    Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...

  4. Codeforces Beta Round #75 (Div. 2 Only)

    Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...

  5. Codeforces Beta Round #74 (Div. 2 Only)

    Codeforces Beta Round #74 (Div. 2 Only) http://codeforces.com/contest/90 A #include<iostream> ...

  6. Codeforces Beta Round #73 (Div. 2 Only)

    Codeforces Beta Round #73 (Div. 2 Only) http://codeforces.com/contest/88 A 模拟 #include<bits/stdc+ ...

  7. Codeforces Beta Round #72 (Div. 2 Only)

    Codeforces Beta Round #72 (Div. 2 Only) http://codeforces.com/contest/84 A #include<bits/stdc++.h ...

  8. Codeforces Beta Round #67 (Div. 2)

    Codeforces Beta Round #67 (Div. 2) http://codeforces.com/contest/75 A #include<bits/stdc++.h> ...

  9. Codeforces Beta Round #65 (Div. 2)

    Codeforces Beta Round #65 (Div. 2) http://codeforces.com/contest/71 A #include<bits/stdc++.h> ...

随机推荐

  1. Java21个基础知识点

    类装载器就是寻找类的字节码文件,并构造出类在JVM内部表示的对象组件.在Java中,类装载器把一个类装入JVM中,要经过以下步骤: (1) 装载:查找和导入Class文件: (2) 链接:把类的二进制 ...

  2. 原始套接字&&数据链路层访问

    1. 原始套接字能力: (1) 进程可以读写ICMP,IGMP等分组,如ping程序: (2) 进程可以读写内核不处理协议字段的ipv4数据报:如OSPF等: (3) 进程可以使用IP_HDRINCL ...

  3. pycaffe做识别时通道转换问题

    转自---------------------  作者:Peanut_范  来源:CSDN  原文:https://blog.csdn.net/u013841196/article/details/7 ...

  4. Git——Git常用命令速查表

  5. FineReport——JS监听其他控件事件

    首先在参数面板和报表中分布添加一个button,用于被监听: 参数面板 控件名:temp: temp点击事件:alert("temp"); 报表 控件名:exprt: temp点击 ...

  6. 在ie10中如何禁用输入框中的小眼睛 与 叉叉 删除按钮

    修改本地组策略,禁用密码输入框中的密码显示: 切换成IE兼容模式:(此方法仅在Windows 7下有效,Windows 8无效) 那是系统自己支持的,有时候很方便,有时候会影响文本框里的文本,提供一个 ...

  7. mybatis 联结查询

    一.查询 员工(tbl_employee)时,关联 查询出 员工对于的部门信息 (tab1_dept),一对一查询,或者多对一查询 适用 emp bean里面 包含 部门bean dept属性对象 1 ...

  8. Elasticsearch源码分析(一)启动流程 ModuleBuilder injector

    http://blog.csdn.net/u010994304/article/details/50452890 es启动脚本是bin目录下的elasticsearch. 脚本内容不再赘述,java主 ...

  9. MapReduce案例二:好友推荐

    1.需求 推荐好友的好友 图1: 2.解决思路 3.代码 3.1MyFoF类代码 说明: 该类定义了所加载的配置,以及执行的map,reduce程序所需要加载运行的类 package com.hado ...

  10. 《java并发编程实战》读书笔记4--基础构建模块,java中的同步容器类&并发容器类&同步工具类,消费者模式

    上一章说道委托是创建线程安全类的一个最有效策略,只需让现有的线程安全的类管理所有的状态即可.那么这章便说的是怎么利用java平台类库的并发基础构建模块呢? 5.1 同步容器类 包括Vector和Has ...