【题解】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进制(数字)互相转换解决问题
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | #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; } |
作者: bbqub
出处:https://www.cnblogs.com/bbqub/p/8709611.html
版权:本站使用「CC BY 4.0」创作共享协议,转载请在文章明显位置注明作者及出处。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发中对象命名的一点思考
· .NET Core内存结构体系(Windows环境)底层原理浅谈
· C# 深度学习:对抗生成网络(GAN)训练头像生成模型
· .NET 适配 HarmonyOS 进展
· .NET 进程 stackoverflow异常后,还可以接收 TCP 连接请求吗?
· 本地部署 DeepSeek:小白也能轻松搞定!
· 基于DeepSeek R1 满血版大模型的个人知识库,回答都源自对你专属文件的深度学习。
· 在缓慢中沉淀,在挑战中重生!2024个人总结!
· 大人,时代变了! 赶快把自有业务的本地AI“模型”训练起来!
· Tinyfox 简易教程-1:Hello World!