1B. Spreadsheets
2015-09-24 23:58
197 查看
题目大意:
行和列的两种方式。
A是1, B是2,....Z是26, AA是27, AB是28...........
如: BC23代表55列23行
还有一种表示方法:R23C55, 代表23行,55列。
要求这两种数字之间相互转化。
=========================================================================
需要注意的就是两点:
1. 每个数字对26取余数后要再 - 1,再+‘A’ 就是答案了。
2. 如果余数是0则要对C--,并且输出的字符是Z、
行和列的两种方式。
A是1, B是2,....Z是26, AA是27, AB是28...........
如: BC23代表55列23行
还有一种表示方法:R23C55, 代表23行,55列。
要求这两种数字之间相互转化。
=========================================================================
需要注意的就是两点:
1. 每个数字对26取余数后要再 - 1,再+‘A’ 就是答案了。
2. 如果余数是0则要对C--,并且输出的字符是Z、
#include <iostream> #include <cmath> #include <algorithm> #include <string> #include <cstring> #include <cstdio> #include <vector> #include <cstdlib> using namespace std; typedef long long LL; const LL INF = 0xffffff; const int maxn = 201315; const LL MOD = 1e9+7; void Putt(int C) { if(C == 0) return ; if(C%26 == 0) Putt((C-1)/26); else Putt(C/26); char ch; if(C%26 == 0) ch = 'Z'; else ch = C%26 + 'A' - 1; printf("%c", ch); } void ChangeOne(char str[]) { int R, C; sscanf(str,"R%dC%d", &R, &C); Putt(C); printf("%d\n", R); } void ChangeTow(char str[]) { int num = 0, i; for(i=0; str[i] >= 'A' && str[i] <= 'Z'; i++) { num = num*26 + str[i] - 'A' + 1; } printf("R%sC%d\n",str+i, num); } bool Ok(char str[]) { if(str[0] == 'R' && str[1] >= '0' && str[1] <= '9') { for(int i=1; str[i]; i++) { if(str[i] == 'C') return true; } } return false; } int main() { int T; char str[105]; scanf("%d", &T); while(T--) { cin >> str; if(Ok(str)) ChangeOne(str); else ChangeTow(str); } return 0; } /* 26 Z 27 AA 53 BA BZ 78 CA 79 */
相关文章推荐
- shell脚本作业
- Linux下安装jdk8步骤详述
- 机器学习-k近邻算法
- 黑马程序员--多线程
- cs
- JAVA API文档(非chm版)
- nagios(centreon)监控lvs
- 【巧用百度地图】—百度地图生成器(直接获取代码)
- CentOS-6.5安装配置Tengine
- go(golang) dns 解析源码 go/src/net/dnsclient_unix.go 分析
- Scala深入浅出进阶经典 第41讲:List继承体系实现内幕和方法操作源码揭秘
- ABP之模块分析
- git config
- Oracle 分析函数的使用(主要是rollup用法)
- 1A Theatre Square
- 一切成功源于积累——20150924 美国耐用品订单符合预期为负值 黄金1小时1600点
- XHTML5 ----- 表单验证(用户名、密码和email检测)
- 字符串的拼接和拷贝的实现
- sublime 快捷键
- MySQL中的索引初步介绍