CF1B 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行,每行一个被转换的坐标。
输入格式:
2
R23C55
BC23
输出格式:
BC23
R23C55
分析:这道题其实挺简单的,想到就是将十进制的数转换为二十六进制就可以了,然后注意一下当n2%26==0的时候是'A'就可以了
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
using namespace std;
char a[]; void solve1(){
int len=strlen(a);
int i;
int n1=,n2=;
int flag=;
for( i=; i<len; i++ ){
if(a[i]>=''&&a[i]<=''&&flag==){
n1=n1*+(a[i]-'');
}
else if(a[i]>=''&&a[i]<=''&&flag==){
n2=n2*+(a[i]-'');
}
else{
flag=;
}
}
// cout<<"n1="<<n1<<" n2="<<n2<<endl;
char temp[];
int pos=;
while(n2!=){
int t=n2%;
if(t==) temp[pos++]='A';
else{
temp[pos++]=(char)(+t-);
}
n2/=;
}
for( int i=pos-; i>=; i-- ){
cout<<temp[i];
}
cout<<n1<<endl;
} void solve2(){
// cout<<a<<endl;
int len=strlen(a);
int t=;
for( int i=; i<len; i++ ){
if(!(a[i]>='A'&&a[i]<='Z')){
t=i-;
break;
}
}
double m2=;
for( int i=; i<=t; i++ ){
m2=m2+(a[i]-'A'+)*(pow(,(t-i)));
// cout<<"a[i]-'A'+1="<<a[i]-'A'+1<<" "<<pow(26,(t-i))<<endl;
// cout<<"m2="<<m2<<endl;
}
cout<<'R';
for( int i=t+; i<len; i++ ){
cout<<a[i];
}
cout<<'C'<<m2<<endl;
} int main(){
int n;
cin>>n;
while(n--){
cin>>a;
if(a[]=='R'&&a[]>=''&&a[]<=''){
// cout<<a<<endl;
solve1();
}
else{
solve2();
}
}
return ;
}
但是在做这道题的时候有个很气愤的事,如果你把52行的double m2=0;改成int m2=0;(笔者实在codeblocks,,,MINGW编译器下跑的程序),会发现结果是不对的,样例二得出结果是m2=51
这个去看了下pow函数的源码,。。。。问了下大佬们,pow是很玄学的东西,所以大家在写东西的时候尽量避开pow函数,自己写个for循环鸭,也不长。。。
CF1B Spreadsheets的更多相关文章
- CF1B.Spreadsheets(电子表格) 题解 模拟
作者:zifeiy 标签:模拟 题目出处:Spreadsheets 题目描述 在流行的电子表格系统中(例如,在Excel中),使用如下计算方式来对列号进行计算. 第1列对应A,第2列对应B,--,第2 ...
- cf------(round)#1 B. Spreadsheets(模拟)
B. Spreadsheets time limit per test 10 seconds memory limit per test 64 megabytes input standard inp ...
- CF Spreadsheets (数学)
Spreadsheets time limit per test 10 seconds memory limit per test 64 megabytes input standard input ...
- Spreadsheets
很水的一道题,提醒自己要认真,做的头都快晕了.考虑26的特殊情况. D - Spreadsheets Time Limit:10000MS Memory Limit:65536KB 6 ...
- codeforces 1B Spreadsheets
In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is u ...
- Codeforces Beta Round #1 B. Spreadsheets 模拟
B. Spreadsheets 题目连接: http://www.codeforces.com/contest/1/problem/B Description In the popular sprea ...
- B. Spreadsheets(进制转换,数学)
B. Spreadsheets time limit per test 10 seconds memory limit per test 64 megabytes input standard inp ...
- C#-使用GoogleAPI读写spreadsheets
https://docs.google.com/spreadsheets/在线使用一些常用办公工具,比如excel. 如需要C#代码自动读写这些excel,则需要使用GoogleAPI. 封装的公用类 ...
- 【题解】codeforces 1B Spreadsheets
题意翻译 人们常用的电子表格软件(比如: Excel)采用如下所述的坐标系统:第一列被标为A,第二列为B,以此类推,第26列为Z.接下来为由两个字母构成的列号: 第27列为AA,第28列为AB-在标为 ...
随机推荐
- Javascript 字符串(一)常见函数使用
一.js字符串示例1 <script type="text/javascript"> var strobject = new String('123abc123abc' ...
- Map network drive遇到报错“The network folder specified is currently mapped using a different user name and password”,怎么办?
--------------------------- Windows --------------------------- The network folder specified is curr ...
- 用 tensorflow实现DeepFM
http://www.fabwrite.com/deepfm 文章DeepFM: A Factorization-Machine based Neural Network for CTR Predic ...
- Win10系统的SurfacePro4无法修改启动顺序怎么办
必须要把底部的开关关闭,否则启动顺序无法修改
- shell编程学习笔记(八):Shell中if判断的使用
一.if的语法: 1.单分支语句结构 if [ 条件表达式 ]; then 指令 fi 2.双分支语句结构 if [ 条件表达式 ]; then 指令一 else 指令二 fi 3.多分支语句结构 i ...
- If 条件左边写常量?
if判断时,常量最好写左边 例如: 编程规范反复强调变量放在双等号的右边,常量放在左边,就是为了规避出现 If (ulCnt = 0)这种语法正确,但是极有可能是笔误的情况.为了杜绝这种不必要的逻 ...
- mybatis检测mysql表是否存在
1.优先使用information_schema来检查,如果没有查询这个的权限则使用show tables来检查. mapper: import java.util.Map; import org.a ...
- go微服务框架go-micro深度学习(一) 整体架构介绍
产品嘴里的一个小项目,从立项到开发上线,随着时间和需求的不断激增,会越来越复杂,变成一个大项目,如果前期项目架构没设计的不好,代码会越来越臃肿,难以维护,后期的每次产品迭代上线都会牵一发而动全身.项目 ...
- OpenLayers WorkShop 快速学习通道
学习地址:https://openlayers.org/workshop/en/ OpenLayers Workshop Introduction Basics Creating a map Zoom ...
- Android 6.0 动态权限申请注意事项
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/uana_777/article/details/54136255 Part One 权限区分 And ...