codeforces
来源:互联网 发布:穿衣服搭配软件 编辑:程序博客网 时间:2024/06/06 09:41
题意:
将R23C55(第23行55列)转换成另一种表达形式BC23,即将行用字母表示,A到Z(26位),下一位为AA(27),再例如BZ(2*26+26=78)。
以及将形如BC23转换成R23C55。
思路:
模拟一发即可。要注意判断到底是Excel转换成RXCY还是RXCY转换成Excel,不可以单纯的判断首字母为R,第二个字母为数字,就断定为是将RXCY转换成Excel格式。
代码:
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <stack>using namespace std;const int MAXN = 1e6 + 10;int len;char str[MAXN];void one(){int pos, a=0, b=0;for(int i=0; i<len; ++i){if(str[i]=='C') {pos = i;break;}}for(int i=1; i<pos; ++i){a = a*10+(str[i]-'0');}for(int i=pos+1; i<len; ++i){b = b*10+(str[i]-'0');}stack<char> s;while(b>0){ if(b%26==0){ s.push('Z'); b -= 26; } else s.push('A'-1+b%26); b/=26;}while(!s.empty()){ printf("%c", s.top()); s.pop();}printf("%d\n", a);}void two(){int pos;for(int i=0; i<len; ++i){if(isdigit(str[i])){pos = i; break;}}int num = 0;for(int i=0; i<pos-1; ++i){num = num*26 + (str[i]-'A'+1)*26;}num += str[pos-1]-'A';printf("R");for(int i=pos; i<len; ++i) printf("%c", str[i]);printf("C%d\n", num+1);}int main(){int n;scanf("%d", &n);while(n--){ getchar();scanf("%s", str);len = strlen(str);bool aa = false;bool bb = false;for(int i=0; i<len; ++i){ if(isdigit(str[i])) aa = true; if(aa && isalpha(str[i])){ bb = true; break; }}if(bb)one();elsetwo();}return 0;}
0 0
- codeforces~~~
- Codeforces
- codeforces
- Codeforces
- codeforces
- codeforces
- Codeforces
- Codeforces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- 正则表达式的三种模式
- Thinking in SQL系列之六:数据挖掘Apriori关联分析再现啤酒尿布神话
- 最全的常用正则表达式大全——包括校验数字、字符、一些特殊的需求等等
- java基础语法
- Linux 安全加固之vsftp(ftp)升级步骤详解
- codeforces
- Java中转UTC时间字符串(含有T Z)为local时间(2017-01-22T09:28:33Z)
- 倩倩的test啦啦啦
- 手把手教你从零实现Linux misc设备驱动一(基于友善之臂4412开发板)
- 【git】git分支branch和标签tag之增删改查
- ESP8266--学习笔记(五)TCP通信--TCP-Server
- LeetCode——Trapping Rain Water
- 倩倩的test啦啦啦
- Eclipse安装Spring插件 学习SpringBoot的应该用的到 -这个一定要记录下来