CF Spreadsheets (数学)
10 seconds
64 megabytes
standard input
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.
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.
Write n lines, each line should contain a cell coordinates in the other numeration system.
2
R23C55
BC23
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 (数学)的更多相关文章
- CF Exam (数学)
Exam time limit per test 1 second memory limit per test 256 megabytes input standard input output s ...
- 第18章-x86指令集之常用指令
x86的指令集可分为以下4种: 通用指令 x87 FPU指令,浮点数运算的指令 SIMD指令,就是SSE指令 系统指令,写OS内核时使用的特殊指令 下面介绍一些通用的指令.指令由标识命令种类的助记符( ...
- 【JVM源码解析】模板解释器解释执行Java字节码指令(上)
本文由HeapDump性能社区首席讲师鸠摩(马智)授权整理发布 第17章-x86-64寄存器 不同的CPU都能够解释的机器语言的体系称为指令集架构(ISA,Instruction Set Archit ...
- B. Spreadsheets(进制转换,数学)
B. Spreadsheets time limit per test 10 seconds memory limit per test 64 megabytes input standard inp ...
- CF 990A. Commentary Boxes【数学/模拟】
[链接]:CF [题意]:对于一个数n,每次加一的代价是a,每次减一的代价是b,求被m整除时的最小代价. [分析]:分情况讨论,自己多举几个栗子. [代码]: #include<cstdio&g ...
- 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 ...
- cf.295.C.DNA Alignment(数学推导)
DNA Alignment time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- CF Amr and Pins (数学)
Amr and Pins time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- CF Polycarpus' Dice (数学)
Polycarpus' Dice time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
随机推荐
- Linux下文件的权限
一.Linux下查看文件属性 命令为: [root@localhost ~]# ls -al 结果: ls是『list』的意思,重点在显示文件的文件名与相关属性.而选项『-al』则表示列出所有的文件详 ...
- Java IO (5) - 总结
Java IO (5) - 总结 0. 目录 FileInputStream FileOutputStream FileReader FileWriter BufferedReader Buffere ...
- SaltStack安装(CentOS7.x)
安装基础: 参考文档:https://docs.saltstack.com/en/latest/topics/installation/rhel.html 1.导入SaltStack仓库key: wg ...
- API基础开发学习网址
http://www.cnblogs.com/shanyou/category/307401.html http://www.cnblogs.com/beginor/archive/2012/03/1 ...
- windows下实现微秒级的延时
windowsintegeriostream汇编嵌入式任务 最近正在做一个嵌入式系统,是基于windows ce的,外接硬件的时序要微秒级的延时.1.微秒级的延时肯定不能基于消息(SetTimer函数 ...
- C#全角半角转换函数
Code#region 全角半角转换 /// <summary> /// 转全角的函数(SBC case) /// </summary> /// <param name= ...
- Angularjs 整体框架结构
//angulajs整体代码框架结构/** * @license AngularJS v1.2.6 * (c) 2010-2014 Google, Inc. http://angularjs.org ...
- C#多线程开发
1.进程与线程的区别 通俗的讲,进行就是任务管理器中进行列表中看到的正在运行的程序,它是一个动态的概念,活动的实体. 线程是程序执行流的最小单元,是线程中一个实体,是系统独立调度和分派CPU基本单位. ...
- sql2008“备份集中的数据库备份与现有数据库不同”解决方法
因为是在另一台电脑对同名数据库做的备份,用常规方法还原,提示不是相同数据库,不让还原,在网上找到下面的方法解决了: 一.右击系统数据库master,新建查询 执行以下SQL代码: RESTORE DA ...
- C#的枚举数(Enumerator)和可枚举类型(Enumerable)
数组可以被foreach语句遍历数组中的元素,原因是数组可以按需提供一个叫做枚举数(enumerator)的对象.枚举数可以依次返回请求的数组的元素. 对于有枚举数的类型而言,必须有一个方法来获取它们 ...