【题解】codeforces 1B Spreadsheets
题意翻译
人们常用的电子表格软件(比如: Excel)采用如下所述的坐标系统:
第一列被标为A,第二列为B,以此类推,第26列为Z。接下来为由两个字母构成的列号: 第27列为AA,第28列为AB…在标为ZZ的列之后则由三个字母构成列号,如此类推。
行号为从1开始的整数。
单元格的坐标由列号和行号连接而成。比如,BC23表示位于第55列23行的单元格。
有时也会采用被称为RXCY的坐标系统,其中X与Y为整数,坐标(X,Y)直接描述了对应单元格的位置。比如,R23C55即为前面所述的单元格。
您的任务是编写一个程序,将所给的单元格坐标转换为另一种坐标系统下面的形式。
输入
第一行一个整数n(1<=n<=10^5),表示将会输入的坐标的数量。
接下来n行,每行一个坐标。
注意: 每个坐标都是正确的。此外不会出现行号或列号大于10^6的单元格。
输出
n行,每行一个被转换的坐标。
题目描述
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 n n ( 1<=n<=105 1<=n<=10^{5} 1<=n<=105 ), the number of coordinates in the test. Then there follow n n 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 10^{6} 106 .
输出格式:
Write n n n lines, each line should contain a cell coordinates in the other numeration system.
输入输出样例
输入样例#1: 复制
2
R23C55
BC23
输出样例#1: 复制
BC23
R23C55
思路
题目给出了两种行列位置的表示方法,一个是Excel表示法,一个是(R,C)坐标表示法,我们要做的就是将输入的一种表示转换成另一种表示再输出。
可以通过26进制(字母)与10进制(数字)互相转换解决问题
#include<cmath>
#include<cctype>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define re register int
using namespace std;
inline int read(){
int x=0,w=1;
char ch=getchar();
while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
if(ch=='-') w=-1,ch=getchar();
while(ch>='0'&&ch<='9') x=(x<<1)+(x<<3)+ch-48,ch=getchar();
return x*w;
}
const char *Const=" ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char s[101]; inline void Solve1() {
int i=0,j=0,num1=0,num2=0;
int t[101];
for(++i;isdigit(s[i]);++i) num2=num2*10+s[i]-'0';
for(++i;s[i];++i) num1=num1*10+s[i]-'0';
for(;num1;num1=num1/26-!(num1%26)) {
if(num1%26) t[++j]=num1%26;
else t[++j]=26;
}
for(;j;--j) putchar(Const[t[j]]);
printf("%d\n",num2);
} inline void Solve2() {
int i=0,num1=0,num2=0;
for(;isupper(s[i]);++i) (num2*=26)+=s[i]-'A'+1;
for(;s[i];++i) (num1*=10)+=s[i]-'0';
printf("R%dC%d\n",num1,num2);
} int main() {
//freopen("1b.in","r",stdin);
//freopen("1b.out","w",stdout);
int n;
bool flag;
n=read();
for(re i=1;i<=n;++i) {
scanf("%s",s);
flag=0;
for(int i=0;s[i]&&!flag;++i) if(i&&isdigit(s[i-1])&&isupper(s[i])) flag=1; //若字母前出现数字,一定是(R,C)法
if(flag) Solve1();
else Solve2();
}
return 0;
}
【题解】codeforces 1B Spreadsheets的更多相关文章
- codeforces 1B Spreadsheets
In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is u ...
- CodeForces 1B Spreadsheets (字符串处理,注意细节,大胆尝试)
题目 注意模后余数为0时,要把除以26后的新数据减1,为什么这样,要靠大胆尝试.我在对小比赛中坑了一下午啊,直到比赛结束也没写出这道题....要死了.. #include<stdio.h> ...
- CodeForces 1B 模拟题。
H - 8 Time Limit:10000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- 【Codeforces 1B】Spreadsheets
[链接] 我是链接,点我呀:) [题意] A~Z分别对应了1~26 AA是27依次类推 让你完成双向的转换 [题解] 转换方法说实话特别恶心>_< int转string 得像数位DP一样一 ...
- [题解] Codeforces Round #549 (Div. 2) B. Nirvana
Codeforces Round #549 (Div. 2) B. Nirvana [题目描述] B. Nirvana time limit per test1 second memory limit ...
- 题解——CodeForces 438D The Child and Sequence
题面 D. The Child and Sequence time limit per test 4 seconds memory limit per test 256 megabytes input ...
- codeforces 1B 模拟
题目大意: 给出两种行列位置的表示方法,一个是Excel表示法,一个是(R,C)坐标表示.给出一种表示,输出另外一种表示. 基本思路: 模拟,首先判断是哪一种表示法,然后转换成另外一种表示方法: 我做 ...
- [题解][Codeforces]Good Bye 2019 简要题解
构造题好评,虽然这把崩了 原题解 A 题意 二人游戏,一个人有 \(k_1\) 张牌,另一个人 \(k_2\) 张,满足 \(2\le k_1+k_2=n\le 100\),每张牌上有一个数,保证所有 ...
- [题解][Codeforces]Codeforces Round #602 (Div. 1) 简要题解
orz djq_cpp lgm A 题意 给定一个分别含有 \(\frac n2\) 个左括号和右括号的括号序列 每次可以将序列的一个区间翻转 求一个不超过 \(n\) 次的操作方案,使得操作完之后的 ...
随机推荐
- 二、jmeter模拟请求头及监听器之结果树
一.模拟请求头 利用jmeter发送http请求时,被接收的服务端会对发送的该请求进行初步判断,如果不是web端发送的请求就会被打回导致请求不通,这时候需要模拟请求头,模拟正常的用户行为进行发送请求 ...
- Java对象内存分布
[deerhang] 创建对象的四种方式:new关键字.反射.Object.clone().unsafe方法 new和反射是通过调用构造器创建对象的,创建对象的时候使用invokespecial指令 ...
- Gentoo 后的几个细节的完善
Gentoo 后的几个细节的完善 目录 Gentoo 后的几个细节的完善 细节一:引导分区与 cdrom 开机正确挂载 细节二:可预见的命名规则的网络接口名称改为传统的 eth0 细节三:为管理员用户 ...
- 华为eNSP模拟器— telnet实验
华为eNSP模拟器-telnet实验 一.实验一 路由交换之间实现telnet登陆 实验拓扑 实验目的: 路由器作为 telnet 服务器 交换机作为客户端去连接路由器 实验步骤: 路由器配置 < ...
- Python基础 小白[7天]入门笔记
笔记来源 Day-1 基础知识(注释.输入.输出.循环.数据类型.随机数) #-*- codeing = utf-8 -*- #@Time : 2020/7/11 11:38 #@Author : H ...
- 搭建LAMP环境部署Nextcloud私人网盘
搭建 LAMP 环境部署 Nextcloud 私人网盘 前言 Nextcloudd 是一个开源的.基于本地的文件共享和协作平台,它允许您保存文件并通过多个设备(如PC.智能手机和平板电脑)访问它们. ...
- Ansible_变量管理与设置
一.Ansible变量管理 1.变量概述 Ansible支持利用变量来存储值,并在Ansible项目的所有文件中重复使用这些值.这可以简化项目的创建和维护,并减少错误的数量 通过变量,可以轻松地在An ...
- .NET Core中插件式开发实现
前言: 之前在文章- AppDomain实现[插件式]开发 中介绍了在 .NET Framework 中,通过AppDomain实现动态加载和卸载程序集的效果. 但是.NET Core 仅支持单个默认 ...
- 微信小程序使用同声传译实现语音识别功能
我使用同声传译语音识别功能是为了实现微信小程序首页的语音搜索功能,如果你也是那么恭喜你,你可以ctrl+c.ctrl+v再改一改,如果你不是那么你也不要着急的走可以看完我的文章会对你有所帮助! 首先是 ...
- 痞子衡嵌入式:改动i.MXRT1xxx里IOMUXC_GPR寄存器保留位可能会造成系统异常
大家好,我是痞子衡,是正经搞技术的痞子.今天痞子衡给大家介绍的是改动i.MXRT1xxx里IOMUXC_GPR寄存器保留位可能会造成系统异常. 痞子衡的嵌入式技术交流群里有一位非常活跃的朋友(网名:文 ...