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-在标为 ...
随机推荐
- idea插件actiBPM源码
actiBPM https://github.com/Activiti/Activiti
- bcrypt 加密
关于 bcrypt:1.bcrypt是不可逆的加密算法,无法通过解密密文得到明文.2.bcrypt和其他对称或非对称加密方式不同的是,不是直接解密得到明文,也不是二次加密比较密文,而是把明文和存储的密 ...
- windows10开启hyper-v虚拟化
windows积极融入虚拟化,对pc体验很不错的! 01.程序更新组件 控制面板--->程序-->打开/关闭 windwods功能--->更新完毕,重启windows 02.确认是否 ...
- 高仿MT4行情终端(K线图+操控+简单架构)
技术:VS2015 Update3 + QT 5.11.2 + BOOST 1.68 + QT VS Tools + C++11 概述 模仿外汇MT4的界面 详细 代码下载:http://www. ...
- 【C++】C++中的函数
目录结构: contents structure [-] 简介 可变形参的函数 initializer_list形参 省略符形参 main函数处理命令行选项 函数指针与函数引用 inline内联函数 ...
- Linksys WRT610n V2 刷ddwrt后安装entware-ng,使用opkg
安装步骤很简单,首先启用usb.jffs.等. 然后: mkdir -p /jffs/opt mount -o bind /jffs/opt /opt wget -O - http://pkg.ent ...
- CentOS5.5上安装Python2.7及ez_setup和pip包
CentOS5.5上安装Python2.7及ez_setup和pip包 下载 首先从Python官方下载源代码包下载 编译安装 这里将python安装到/opt/python27文件夹下 tar xv ...
- 解决Protobuf生成的C#代码命名不规范问题
起因 通常使用Protobuf的步骤为 定义 .proto 文件 使用 protoc 生成对应语言的代码 以生成C#代码为例,使用如下命令: protoc -I ../protos --csharp_ ...
- k8s yaml说明
k8s yaml # yaml格式的pod定义文件完整内容: apiVersion: v1 #必选,版本号,例如v1 kind: Pod #必选,Pod metadata: ...
- 自定义命令杀死 java 进程 alias kjava
alias kjava='ps -ef|grep ProcessName |awk "{print $2}"|xargs kill -9' 上面脚本放在杀JAVA进程中,会出现一些 ...