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. 通过编译函数库来学习GCC【转】

    转自:http://blog.csdn.net/u012365926/article/details/51446295 基本概念 什么是库 在windows平台和linux平台下都大量存在着库. 本质 ...

  2. ubuntu下定时弹窗记录工作日志

    背景 记录工作日志,是一个很好的习惯,但不容易坚持,本来打算每天记录,但经常拖延,拖着拖着,有一些事情就忘记了. 等到写周报或月报的时候,才会开始翻邮件,聊天记录,各个仓库的提交log等,回忆都干了些 ...

  3. 解决linux下终端无法输入的假死问题

    有时在linux下shell终端中,会突然出现终端应用卡死,无法接受键盘输入, 但是其它分屏, 系统都是正常的.这本来是一个终端的很老的功能, 叫软件流控制(XON/XOFF flow control ...

  4. 源码分析之tinyhttpd-0.1

    1. 简介: tinyhttpd是使用c语言开发的超轻量级http服务器,通过代码流程可以了解http服务器的基本处理流程, 并且涉及了网络套接字,线程,父子进程,管道等等知识点: 项目地址:http ...

  5. Linux内核基础--事件通知链(notifier chain)good【转】

    转自:http://www.cnblogs.com/pengdonglin137/p/4075148.html 阅读目录(Content) 1.1. 概述 1.2.数据结构 1.3.  运行机理 1. ...

  6. Java GC策略

    本文转自https://blog.csdn.net/rabbit_in_android/article/details/50386954 内存管理和垃圾回收 JVM内存组成结构 JVM栈由堆.栈.本地 ...

  7. VPS性能测试(1):CPU物理个数、内核、超线程、多核心

    1.登录VPS界面,执行:cat /proc/cpuinfo,就会显示出VPS主机的CPU详细参数,如内核.频率.型号等等 2.主要参数physical_id表示物理CPU个数,cpu cores是内 ...

  8. mysql 安装和配置

    mysql 安装: 在命令行输入 sudo apt-get install mysql-server  安装过程中会跳出来一个窗口,输入数据库root用户的密码(必须输入密码) 安装完成后 通过 my ...

  9. Log4Net中配置文件的解释

    一个完整的配置文件的例子如下所示 <log4net> <!-- 错误日志类--> <logger name="logerror"> <le ...

  10. 《逐梦旅程 WINDOWS游戏编程之从零开始》笔记4——Direct3D编程基础

    第11章 Direct3D编程基础 2D游戏是贴图的艺术,3D游戏是渲染的艺术.这句话在我学过了之前的GDI编程之后,前一句算是有所体会,现在是来理解后一句的时候了. 安装DirectX SDK配置啥 ...