cf1b(字符串)

题目链接:http://www.codeforces.com/problemset/problem/1/B

特别有用的一个处理字符串的函数(当然比不上正则表达式的强大)sscanf,直接提取数字,解题相当方便。

View Code
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cmath>
 5 #include<string>
 6 #include<algorithm>
 7 using namespace std;
 8 
 9 void Gets(int y){
10     if(!y)return ;
11     Gets((y-1)/26);
12     putchar('A'+(y-1)%26);
13 }
14 
15 
16 int main(){
17     int _case;
18     scanf("%d",&_case);
19     while(_case--){
20         int x,y;
21         char str[110],*p;
22         scanf("%s",str);
23         if(sscanf(str,"%*c%d%*c%d",&x,&y)==2){
24             Gets(y);
25             printf("%d\n",x);
26         }else {
27             for(x=0,p=str;*p>64;p++){
28                 x=x*26+*p-'A'+1;
29             }
30             printf("R%sC%d\n",p,x);
31         }
32     }
33     return 0;
34 }
原文地址:https://www.cnblogs.com/wally/p/3051576.html