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 ...
随机推荐
- hello, angular
开始系统学习一下angular!首先是hello world.根据官网给出的例子,我们一下做出下面这个东西: <!DOCTYPE html> <html ng-app> < ...
- Hibernate之管理session与批处理
1. Hibernate 自身提供了三种管理Session对象的方法 –Session对象的生命周期与本地线程绑定 –Session 对象的生命周期与JTA事务绑定 –Hibernate 委托程序管理 ...
- ios 移动应用通用逻辑流程
请先看前一篇文章<移动互联网app业务逻辑图>,以便于理解 http://blog.csdn.net/uxyheaven/article/details/14156659 1 start ...
- iOS-图片png
把图片添加到工程里面:就报了108个警告!!! 然后我发现我添加的图片有很多命名是这样子的: xcode去找图片的时候是按照什么方式找的呢????? 还发现有好几张同名的图片..... ------- ...
- 在ASP.NET MVC中的四大筛选器(Filter)及验证实现
http://www.cnblogs.com/artech/archive/2012/08/06/action-filter.html http://www.cnblogs.com/ghhlyy/ar ...
- SQl函数的写法
USE [ChangHong_612]GO/****** Object: UserDefinedFunction [dbo].[FN_GetProdQty] Script Date: 10/08/20 ...
- 如何彻底隐藏iOS7应用的status bar
用xcode5开发新的iOS游戏,发现一个坑爹的现象,虽然我已经在info.plist里面把Status bar is initially hidden设置成了YES,但在设备上一跑还是看到丑陋的st ...
- eclipse 安装scons
http://www.sconsolidator.com/update Installation To use SConsolidator, you first have to install SC ...
- javascript --学习this
this 在一般的强类型语言中,this指向的是这个对象本身,可在javascript中 this的取值是执行上下文环境的一部分 其实这个this并不是很难立即,只要记住二点就可以了 那就是谁call ...
- CGContext绘图
0 CGContextRef context = UIGraphicsGetCurrentContext(); 设置上下文 1 CGContextMoveToPoint 开始画线 2 CGContex ...