CodeForces 1B. Spreadsheets(模拟)
题目链接:http://codeforces.com/problemset/problem/1/B
题意:
对换两种不同的表示方法表示行列!
代码例如以下:
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn = 117; typedef __int64 LL; int is_letter(char c) { if(c >= 'A' && c <= 'Z') return 1; return 0; } int is_num(char c) { if(c >='0' && c <='9') return 1; return 0; } int main() { LL t; char s[maxn]; scanf("%I64d",&t); getchar(); while(t--) { gets(s); int len = strlen(s); int k = 0; for(int i = 0; i < len; i++) { if(is_letter(s[i]) && is_num(s[i+1])) { k++; } } if(k == 2)//R23C55形式 { LL i, j; LL t1 = 0, t2 = 0; for(i = 1; ; i++) { if(is_num(s[i])) t1 = t1*10+s[i]-'0'; else break; } for(j = i+1; j < len; j++) { if(is_num(s[j])) t2 = t2*10+s[j]-'0'; else break; } //printf("t1::%I64d t2::%I64d\n",t1,t2); char a[maxn]; i = 0; while(t2) { LL tt = t2%26; a[i++] = tt+'A'-1; t2/=26; if(tt == 0)//注意 { t2--; a[i-1] = 'Z'; } } for(j = i-1; j >= 0; j--) { printf("%c",a[j]); } printf("%I64d\n",t1); } else//BC23形式 { LL i, j; LL t3 = 0, t4 = 0; for(i = 0; ; i++) { if(is_num(s[i])) break; t3 = t3*26+(s[i]-'A'+1); } for(j = i; j < len; j++) { t4 = t4*10+s[j]-'0'; } printf("R%I64dC%I64d\n",t4,t3); } } return 0; } /* 99 R23C55 BC23 R26C78 BZ26 */