Codeforces Beta Round #1 B. Spreadsheets
2016-08-15 01:07
337 查看
题意:两种表示行列的格式之间的相互转换。第一种格式AA123 表示AA表示第27列123表示123行 以此类推 第二种格式:R123C23表示第23列123行
思路:首先分辨出是哪种类型的字符串,然后根据字母表示相当于26进制的思路进行转换。
思路:首先分辨出是哪种类型的字符串,然后根据字母表示相当于26进制的思路进行转换。
#include <iostream> #include <stdio.h> #include <algorithm> #include <string.h> #include <math.h> #include <queue> #include <vector> #include <map> using namespace std; typedef long long LL; typedef unsigned long long UL; #define MS(x,y) memset(x,y,sizeof(x)) #define rpt(i,l,r) for(int i=l;i<=r;i++) #define rpd(i,r,l) for(int i=r;i>=l;i--) LL gcd(LL a,LL b){ return b==0?a:gcd(b,a%b);} #define N 1000005 int main(){ int n; scanf("%d",&n); while(n--){ char str ; scanf("%s",str); int kind=0; int len=strlen(str); for(int i=0;i<len;i++){ if(kind==0&&str[i]<='9'&&str[i]>='0') kind=1; if(kind==1&&str[i]=='C') kind=2; } if(kind==1){ int k=1; int r=0; printf("R"); int i=0; char temp[100]; int pos=0; while(str[i]>='A'&&str[i]<='Z'){ temp[pos]=str[i]; pos++; i++; } for(int j=pos-1;j>=0;j-- ){ r=r+(temp[j]-'A'+1)*k; k=k*26; } while(str[i]!='\0'){ printf("%c",str[i]); i++; } printf("C%d\n",r); } if(kind==2){ int r=0; int c=0; int i=1; while(str[i]!='C'){ r=r*10+str[i]-'0'; i++; } i++; while(str[i]!='\0'){ c=c*10+str[i]-'0'; i++; } char temp[1000]; int pos=0; while(c!=0){ if(c%26==0) temp[pos]='Z'; else temp[pos]=c%26-1+'A'; c=(c-1)/26;//这里注意要减1 比如Z=26 如果直接除以26值为1,但应该为0了 pos++; } for(int i=pos-1;i>=0;i--){ printf("%c",temp[i]); } printf("%d\n",r); } } return 0; }
相关文章推荐
- Codeforces Beta Round #1 B. Spreadsheets
- Codeforces Beta Round #1 B. Spreadsheets
- Codeforces Beta Round #1 B. Spreadsheets 模拟
- Codeforces Beta Round #34 (Div. 2) C. Page Numbers
- Codeforces Beta Round #5——D. Follow Traffic Rules
- Codeforces Beta Round #1 A - Theatre Square
- Codeforces Beta Round #1 A,B,C
- Codeforces Beta Round #18 (Div. 2 Only) D - Seller Bob
- Codeforces Beta Round #35 (Div. 2) E. Parade(成段更新)
- Codeforces Beta Round #69 (Div. 2 Only)——A,B,D
- Codeforces Beta Round #43 D. Parking Lot
- Codeforces Beta Round #35 (Div. 2) / 35A Shell Game(模拟)
- 【Codeforces Beta Round 2B】【贪心 DP】The least round way 从(1,1)走到(n,n)乘积尾数0尽可能少
- Codeforces Beta Round #61 (Div. 2) B. Petya and Countryside (DP)
- Codeforces Beta Round #63 (Div. 2)
- Codeforces Beta Round #6 (Div. 2 Only) A. Triangle 水题
- Codeforces Beta Round #92 (Div. 1 Only)
- Codeforces Beta Round #2 练习
- Codeforces Beta Round #1 C Ancient Berland Circus
- Codeforces Beta Round #69 (Div. 2 Only) E题