题意翻译

人们常用的电子表格软件(比如: 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行,每行一个被转换的坐标。

输入格式:

2

R23C55

BC23

输出格式:

BC23

R23C55

分析:这道题其实挺简单的,想到就是将十进制的数转换为二十六进制就可以了,然后注意一下当n2%26==0的时候是'A'就可以了

  1. #include<iostream>
  2. #include<cmath>
  3. #include<algorithm>
  4. #include<cstring>
  5. #include<cstdlib>
  6. using namespace std;
  7. char a[];
  8.  
  9. void solve1(){
  10. int len=strlen(a);
  11. int i;
  12. int n1=,n2=;
  13. int flag=;
  14. for( i=; i<len; i++ ){
  15. if(a[i]>=''&&a[i]<=''&&flag==){
  16. n1=n1*+(a[i]-'');
  17. }
  18. else if(a[i]>=''&&a[i]<=''&&flag==){
  19. n2=n2*+(a[i]-'');
  20. }
  21. else{
  22. flag=;
  23. }
  24. }
  25. // cout<<"n1="<<n1<<" n2="<<n2<<endl;
  26. char temp[];
  27. int pos=;
  28. while(n2!=){
  29. int t=n2%;
  30. if(t==) temp[pos++]='A';
  31. else{
  32. temp[pos++]=(char)(+t-);
  33. }
  34. n2/=;
  35. }
  36. for( int i=pos-; i>=; i-- ){
  37. cout<<temp[i];
  38. }
  39. cout<<n1<<endl;
  40. }
  41.  
  42. void solve2(){
  43. // cout<<a<<endl;
  44. int len=strlen(a);
  45. int t=;
  46. for( int i=; i<len; i++ ){
  47. if(!(a[i]>='A'&&a[i]<='Z')){
  48. t=i-;
  49. break;
  50. }
  51. }
  52. double m2=;
  53. for( int i=; i<=t; i++ ){
  54. m2=m2+(a[i]-'A'+)*(pow(,(t-i)));
  55. // cout<<"a[i]-'A'+1="<<a[i]-'A'+1<<" "<<pow(26,(t-i))<<endl;
  56. // cout<<"m2="<<m2<<endl;
  57. }
  58. cout<<'R';
  59. for( int i=t+; i<len; i++ ){
  60. cout<<a[i];
  61. }
  62. cout<<'C'<<m2<<endl;
  63. }
  64.  
  65. int main(){
  66. int n;
  67. cin>>n;
  68. while(n--){
  69. cin>>a;
  70. if(a[]=='R'&&a[]>=''&&a[]<=''){
  71. // cout<<a<<endl;
  72. solve1();
  73. }
  74. else{
  75. solve2();
  76. }
  77. }
  78. return ;
  79. }

但是在做这道题的时候有个很气愤的事,如果你把52行的double m2=0;改成int m2=0;(笔者实在codeblocks,,,MINGW编译器下跑的程序),会发现结果是不对的,样例二得出结果是m2=51

这个去看了下pow函数的源码,。。。。问了下大佬们,pow是很玄学的东西,所以大家在写东西的时候尽量避开pow函数,自己写个for循环鸭,也不长。。。

CF1B Spreadsheets的更多相关文章

  1. CF1B.Spreadsheets(电子表格) 题解 模拟

    作者:zifeiy 标签:模拟 题目出处:Spreadsheets 题目描述 在流行的电子表格系统中(例如,在Excel中),使用如下计算方式来对列号进行计算. 第1列对应A,第2列对应B,--,第2 ...

  2. cf------(round)#1 B. Spreadsheets(模拟)

    B. Spreadsheets time limit per test 10 seconds memory limit per test 64 megabytes input standard inp ...

  3. CF Spreadsheets (数学)

    Spreadsheets time limit per test 10 seconds memory limit per test 64 megabytes input standard input ...

  4. Spreadsheets

    很水的一道题,提醒自己要认真,做的头都快晕了.考虑26的特殊情况. D - Spreadsheets Time Limit:10000MS     Memory Limit:65536KB     6 ...

  5. codeforces 1B Spreadsheets

    In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is u ...

  6. Codeforces Beta Round #1 B. Spreadsheets 模拟

    B. Spreadsheets 题目连接: http://www.codeforces.com/contest/1/problem/B Description In the popular sprea ...

  7. B. Spreadsheets(进制转换,数学)

    B. Spreadsheets time limit per test 10 seconds memory limit per test 64 megabytes input standard inp ...

  8. C#-使用GoogleAPI读写spreadsheets

    https://docs.google.com/spreadsheets/在线使用一些常用办公工具,比如excel. 如需要C#代码自动读写这些excel,则需要使用GoogleAPI. 封装的公用类 ...

  9. 【题解】codeforces 1B Spreadsheets

    题意翻译 人们常用的电子表格软件(比如: Excel)采用如下所述的坐标系统:第一列被标为A,第二列为B,以此类推,第26列为Z.接下来为由两个字母构成的列号: 第27列为AA,第28列为AB-在标为 ...

随机推荐

  1. idea插件actiBPM源码

    actiBPM https://github.com/Activiti/Activiti

  2. bcrypt 加密

    关于 bcrypt:1.bcrypt是不可逆的加密算法,无法通过解密密文得到明文.2.bcrypt和其他对称或非对称加密方式不同的是,不是直接解密得到明文,也不是二次加密比较密文,而是把明文和存储的密 ...

  3. windows10开启hyper-v虚拟化

    windows积极融入虚拟化,对pc体验很不错的! 01.程序更新组件 控制面板--->程序-->打开/关闭 windwods功能--->更新完毕,重启windows 02.确认是否 ...

  4. 高仿MT4行情终端(K线图+操控+简单架构)

    技术:VS2015 Update3 + QT 5.11.2 + BOOST 1.68 + QT VS Tools + C++11   概述 模仿外汇MT4的界面 详细 代码下载:http://www. ...

  5. 【C++】C++中的函数

    目录结构: contents structure [-] 简介 可变形参的函数 initializer_list形参 省略符形参 main函数处理命令行选项 函数指针与函数引用 inline内联函数 ...

  6. Linksys WRT610n V2 刷ddwrt后安装entware-ng,使用opkg

    安装步骤很简单,首先启用usb.jffs.等. 然后: mkdir -p /jffs/opt mount -o bind /jffs/opt /opt wget -O - http://pkg.ent ...

  7. CentOS5.5上安装Python2.7及ez_setup和pip包

    CentOS5.5上安装Python2.7及ez_setup和pip包 下载 首先从Python官方下载源代码包下载 编译安装 这里将python安装到/opt/python27文件夹下 tar xv ...

  8. 解决Protobuf生成的C#代码命名不规范问题

    起因 通常使用Protobuf的步骤为 定义 .proto 文件 使用 protoc 生成对应语言的代码 以生成C#代码为例,使用如下命令: protoc -I ../protos --csharp_ ...

  9. k8s yaml说明

    k8s yaml # yaml格式的pod定义文件完整内容: apiVersion: v1       #必选,版本号,例如v1 kind: Pod       #必选,Pod metadata:   ...

  10. 自定义命令杀死 java 进程 alias kjava

    alias kjava='ps -ef|grep ProcessName |awk "{print $2}"|xargs kill -9' 上面脚本放在杀JAVA进程中,会出现一些 ...