Spreadsheets
time limit per test

10 seconds

memory limit per test

64 megabytes

input

standard input

output

standard output

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 test(s)
input
2
R23C55
BC23
output
BC23
R23C55

本质是十进制转26进制,难点在于这个26进制是没有零的,因此当当前的n的能被26整除时,置为‘Z’,同时向前借一位,也就是将n减一,因为n减一的效果就是减去26的当前次方。

还有一个更简洁的递归版本,还没有完全理解,理解后补上。

 #include <cstdio>
#include <cctype>
using namespace std; void fx(int);
int main(void)
{
int t,r,c;
char box[]; scanf("%d",&t);
while(t --)
{
scanf(" %s",box);
if(sscanf(box,"%*c%d%*c%d",&r,&c) == )
{
fx(c);
printf("%d\n",r);
}
else
{
int i;
for(c = ,i = ;box[i];i ++)
if(isalpha(box[i]))
c = c * + box[i] - 'A' + ;
else
break;
printf("R%sC%d\n",&box[i],c);
}
} return ;
} void fx(int n)
{
char ans[];
int j = ; while(n)
{
if(n % == )
{
ans[j] = 'Z';
n -= ;
}
else
ans[j] = n % - + 'A';
n /= ;
j ++;
}
while(j --)
printf("%c",ans[j]);
}

CF Spreadsheets (数学)的更多相关文章

  1. CF Exam (数学)

     Exam time limit per test 1 second memory limit per test 256 megabytes input standard input output s ...

  2. 第18章-x86指令集之常用指令

    x86的指令集可分为以下4种: 通用指令 x87 FPU指令,浮点数运算的指令 SIMD指令,就是SSE指令 系统指令,写OS内核时使用的特殊指令 下面介绍一些通用的指令.指令由标识命令种类的助记符( ...

  3. 【JVM源码解析】模板解释器解释执行Java字节码指令(上)

    本文由HeapDump性能社区首席讲师鸠摩(马智)授权整理发布 第17章-x86-64寄存器 不同的CPU都能够解释的机器语言的体系称为指令集架构(ISA,Instruction Set Archit ...

  4. B. Spreadsheets(进制转换,数学)

    B. Spreadsheets time limit per test 10 seconds memory limit per test 64 megabytes input standard inp ...

  5. CF 990A. Commentary Boxes【数学/模拟】

    [链接]:CF [题意]:对于一个数n,每次加一的代价是a,每次减一的代价是b,求被m整除时的最小代价. [分析]:分情况讨论,自己多举几个栗子. [代码]: #include<cstdio&g ...

  6. CF #305(Div.2) D. Mike and Feet(数学推导)

    D. Mike and Feet time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  7. cf.295.C.DNA Alignment(数学推导)

    DNA Alignment time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  8. CF Amr and Pins (数学)

    Amr and Pins time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  9. CF Polycarpus' Dice (数学)

    Polycarpus' Dice time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

随机推荐

  1. Java设计模式系列之命令模式

    命令模式(Command)的定义 将一个请求封装为一个对象,从而可用不同的请求对客户进行参数化:对请求排队或记录日志,以及支持可撤销的操作,将”发出请求的对象”和”接收与执行这些请求的对象”分隔开来. ...

  2. [iOS基础控件 - 6.12.1] QQ菜单管理 UITabBarController 控制器管理

    A.需求 1.类似QQ.微信顶部或者底部的窗口转换导航条 2.给每个页面添加相应内容   B.UITabBarController 1.基本概念: (1)内容高度 iOS7之前内容高度为:屏幕高度 - ...

  3. JMS开发(一):基础理论认知

    JMS全称是Java Message Service.其是JavaEE技术规范中的一个重要组成部分,是一种企业消息处理的规范.它的作用就像一个智能交换机,它负责路由分布式应用中各个组件所发出的消息. ...

  4. 在数据库各种状态下查询DBID的五大类十种方法汇总

    关于DBID: DBID是DataBase IDentifier的缩写,意思就是数据库的唯一标识符. 这个DBID在数据文件头和控制文件都是存在的,可以用于标示数据文件的归属. 对于不同数据库来说,D ...

  5. win8 或 win2008 系统 TFS 打开或获取源代码非常慢

    最近刚更新了win8.1 .打开VS2012后,准备签出个文件,突然发现速度非常慢.打开个TFS目录都要过10多秒才能看到所有子内容.一开始以为是VS的问题更新了U4补丁.结果还是一样.后来googl ...

  6. BaiduMap开发,获取公交站点信息。

    可能有些人会出现无法导入overlayutil的错误,这是因为BaiduMap里面的包把这部分删除掉了,并且官方没有给出说明,这个地方以前也是让我折腾了很久. 不知道现在有没有说明这个问题,如果需要这 ...

  7. ecshop的smarty库还原成smarty原生库方法

    写过ecshop模板的人都晓得,他们是用所谓的dwt的文件来嵌套lbi文件进行模板的彼此调用.在咱们调取数据的时分,ecshop的默许模板只提供给咱们几个简略的句子进行调用,那么有没有办法能够把这个精 ...

  8. python的一些总结3

    好吧 刚刚的2篇文章都很水.. 这篇 也是继续水 在 templates 右键新建 html 文件:如 index.html (输入以下代码) <!DOCTYPE html> <ht ...

  9. .Net语言 APP开发平台——Smobiler学习日志:开发APP时,如何快速地实现屏幕自适应

    最前面的话:Smobiler是一个在VS环境中使用.Net语言来开发APP的开发平台,也许比Xamarin更方便 一.属性介绍 设置控件在客户端屏幕可见并超出客户端屏幕时,是否自动调节高度以适应屏幕高 ...

  10. Android apk程序调用其它的APK程序

    Intent mIntent = new Intent(); ComponentName comp = new ComponentName("启动的APK包名","启动的 ...