博客
关于我
B. Spreadsheets(进制转换,数学)
阅读量:417 次
发布时间:2019-03-06

本文共 2421 字,大约阅读时间需要 8 分钟。

B. 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.

Examples
input
2 R23C55 BC23
output
BC23 R23C55

 

 

 

#include 
#include
#define M 1*10^6+10char str[M];/* 十进制变为二十六进制 */void solve_10_to_26(char str[]){ char re[M]; int p = M - 1; int r, c; sscanf(str, "R%dC%d", &r, &c); re[p--] = 0; while(r) { re[p--] = r % 10 + '0'; r = r/10; } while(c) { re[p--] = (c-1) % 26 + 'A'; c = (c-1)/26; } printf("%s\n", &re[p+1]);}/* 二十六进制变为十进制 */void solve_26_to_10( char str[] ){ char cc[M]; int c = 0; int r; sscanf( str, "%[A-Z]%d", &cc, &r ); int len = strlen(cc); int p = 0; while(p < len) { c = c + cc[p++] - 'A' + 1; c = c * 26; } c = c / 26; printf("R%dC%d\n", r, c);}int main(){ int n; scanf("%d", &n); while(n--) { scanf("%s", &str); int a, b; if ( sscanf(str, "R%dC%d", &a, &b ) == 2) solve_10_to_26(str); else solve_26_to_10(str); } return 0;}
View Code

 

转载地址:http://gltuz.baihongyu.com/

你可能感兴趣的文章
关于GO语言,这篇文章讲的很明白
查看>>
华为云FusionInsight湖仓一体解决方案的前世今生
查看>>
大数据处理黑科技:揭秘PB级数仓GaussDB(DWS) 并行计算技术
查看>>
C++调用Go方法的字符串传递问题及解决方案
查看>>
云原生2.0时代下,DevOps实践如何才能更加高效敏捷?
查看>>
技巧收藏|10个JavaScript常用数组操作方法
查看>>
两种端到端通用目标检测方法
查看>>
云小课 | 守护网络安全不是问题,iptables的四表五链为你开启“八卦阵”
查看>>
LiteOS内核源码分析:任务栈信息
查看>>
23种设计模式之迭代器模式
查看>>
23种设计模式之组合模式
查看>>
mysql zip安装
查看>>
virtualbox中 Kali Linux安装增强功能
查看>>
virtualbox中 Ubuntu挂载共享文件夹
查看>>
Python 内置函数笔记
查看>>
BootStrapTable 错误
查看>>
PHP 脚本不报错
查看>>
代码整洁之道小结
查看>>
悲观锁与乐观锁
查看>>
js new Date 创建时间默认是8点
查看>>