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-在标为 ...
随机推荐
- Metadata获取的三种方式
本文的试验环境为CentOS 7.3,Kubernetes集群为1.11.2,安装步骤参见kubeadm安装kubernetes V1.11.1 集群 0. Metadata 每个Pod都有一些信息, ...
- 20170814 新鲜:EChart新增了日历图,要想办法用起来
比如我可以用下面这个图来展示某个电站的年报,看他之后一年每一天的发电量. 或者是在月报的时候看这个月每天的发电量.这个最妙的时候,他可以通过旁边的图例来筛选,从而产生一个动态的效果. 还有可以在 ...
- sql格式化并高亮
演示地址: https://ryan-miao.github.io/sql-format-with-highlight/index.html 源码: https://github.com/Ryan-M ...
- 【SQL 代码】SQL 语句记录(不定时更新)
1.数值四舍五入,小数点后保留2位 round() 函数是四舍五入用,第一个参数是我们要被操作的数据,第二个参数是设置我们四舍五入之后小数点后显示几位. numeric 函数的2个参数,第一个表示数据 ...
- SSE图像算法优化系列二十三: 基于value-and-criterion structure 系列滤波器(如Kuwahara,MLV,MCV滤波器)的优化。
基于value-and-criterion structure方式的实现的滤波器在原理上其实比较简单,感觉下面论文中得一段话已经描述的比较清晰了,直接贴英文吧,感觉翻译过来反而失去了原始的韵味了. T ...
- 为ExecutorService增加shutdown hook
public class ShutdownHook { private static final ShutdownHook INSTANCE = new ShutdownHook(); private ...
- make[1]: *** [storage/perfschema/unittest/CMakeFiles/pfs_connect_attr-t.dir/all] 错误 2 解决方法
make[2]: *** [storage/perfschema/unittest/pfs_connect_attr-t] 错误 1 make[1]: *** [storage/perfschema/ ...
- Nginx防压力测试
一.ab压力测试方式为: $ab -n 1000 -c 100 http://www.abc.com:80/ 二.直接简单的方法限制同一个IP的并发最大为10:(以宝塔管理工具为例) 1.打开Ngin ...
- 关于在最新的 Visual Studio 2017 版本中使用 Web Deploy 遇到的 SSL 连接错误
错误信息: 无法完成向远程代理 URL 发送请求.请求被中止: 未能创建 SSL/TLS 安全通道. 原因分析: 最新版本的 Visual Studio 中,已经抛弃了 https 协议中旧版 SSL ...
- Linux将yum源设置为阿里云的镜像源
第一步:备份原有镜像源 mv /etc/yum.repo.d/Centos-Base.repo /etc/yum.repo.d/Centos-Base.repo.bak 第二步:下载阿里云的镜像源 w ...