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 ...
随机推荐
- 问题-XE8报Object factory for class{xx-xx-xx-xx-xx} is missing. To register it, you can drop component[TFDGUIxWaitCursor] into your project.
问题现象:XE8开发数据访问程序时放入了FDPhysMSSQLDriverLink1.FDConnection1.FDConnection1.FDQuery1.DBGrid1,设计期没法,运行期报&q ...
- jdk自带发布webservice服务
1.创建要发布的类 package com.test.webserive; import javax.jws.WebService; //targetNamespace定义命名空间 @WebServi ...
- 关于 jquery cookie的用法
东钿微信公众平台新版上线 需要一个引导用户操作步骤.设置一个cookie师傅偶第一次访问此页面 .如果是则跳出用户引导,如果不是,正常显示. 一开始在百度了一段jquery cookie插件,也没仔细 ...
- 剑指OFFER之二进制中1的个数(九度OJ1513)
题目描述: 输入一个整数,输出该数二进制表示中1的个数.其中负数用补码表示. 输入: 输入可能包含多个测试样例.对于每个输入文件,第一行输入一个整数T,代表测试样例的数量.对于每个测试样例输入为一个整 ...
- Unity3D-Baked Lightmapping 示例学习
首先,看一下摄像机的Rendering Paths http://game.ceeger.com/Manual/RenderingPaths.html 可以看出,对于灯光的渲染质量 Deferred ...
- Spring声明式事务的配置~~~
/*2011年8月28日 10:03:30 by Rush */ 环境配置 项目使用SSH架构,现在要添加Spring事务管理功能,针对当前环境,只需要添加Spring 2.0 AOP类库即可.添加 ...
- 【WebForm】Repeater 序列号 在翻页情况下自增
asp.net Repeater控件分页时,序号列翻页重新从1开始计数问题的解决思路及方法: 一般情况下,使用 <%# Container.ItemIndex + 1% > 给序号列来自增 ...
- HTTP Post Request using Apache Commons
Demonstrates an HTTP Post using the Apache Commons HTTP library. Required Libraries: httpcore-4.1.ja ...
- Git Cmd
http://my.oschina.net/sunboy2050/blog/55749
- TreeView节点拖拉操作
//这个拖拽的感觉不对 unit Unit1;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, ...