【CodeForces】[1B]Spreadsheet
2016-04-10 00:07
218 查看
转换类的题目
难度还是有些的
不过一点一点写 感觉还好
可以当作26进制来方便思考转换
#include<stdio.h> #include<string.h> char s[10]; int l; bool judge() { if(s[0]=='R'&&s[1]<='9'&&s[1]>='0') { for(int i=2; i<l; i++) { if(s[i]=='C') return true; } } return false; } int f(int m,int k) { int sum=1; while(k--) sum*=m; return sum; } int main() { int T; scanf("%d",&T); while(T--) { scanf("%s",s); l=strlen(s); if(judge()) { int tc=0; for(int i=0; i<l; i++) { if(s[i]=='C') { tc=i; break; } } int a=0,b=0; for(int i=1; i<tc; i++) { a=a*10+s[i]-'0'; } for(int i=tc+1; i<l; i++) { b=b*10+s[i]-'0'; } char res[10]; int ti=0; while(b) { if(b%26) { res[ti++]='A'-1+b%26; b/=26; } else { res[ti++]='Z'; b/=26; b--; } } for(int i=ti-1; i>=0; i--) printf("%c",res[i]); printf("%d\n",a); } else { int ti=0; for(int i=0; i<l; i++) if(s[i]<='9'&&s[i]>='0') { ti=i; break; } int x=0; for(int i=ti; i<l; i++) x=x*10+s[i]-'0'; printf("R%dC",x); x=0; int k=1; for(int i=0; i<ti; i++) { x+=(s[i]-'A'+1)*f(26,ti-k); k++; } printf("%d\n",x); } } return 0; }
题目地址:【CodeForces】[1B]Spreadsheet
相关文章推荐
- Codeforces Round #197 (Div. 2)
- Codeforces Round #198 (Div. 1)
- Codeforces 405E Codeforces Round #238 (Div. 2)E
- Codeforces 407C Codeforces Round #239 (Div. 1)C
- CodeForces 449A - Jzzhu and Chocolate
- CodeForces 449 B. Jzzhu and Cities
- codeforces 618C. Constellation
- Codeforces Round #265 (Div. 2)
- Codeforces #310 div2 C. Case of Matryoshkas
- 状态压缩DP codeforces 244 Problem C. The Brand New Function 和 codeforces 165 E. Compatible Numbers
- codeforces 16 Problem E fish
- Codeforces Round332 部分题解
- CodeForces 603A_Alternative Thinking (DP)
- CodeForces 602B_Approximating a Constant Range_DP
- Codeforces round #247 for Div. 2
- Codeforces Round #246 (Div. 2)
- Codeforces #264(div 2)D.Gargari and Permutations
- Codeforces Round #236 (Div. 2)------A,B
- codeforces 257 div2 B
- Codeforces Gym100571A Cursed Query