CF1B Spreadsheets

【题解】

  模拟就行,类似进制转换

 1 #include<cstdio>
 2 #include<algorithm>
 3 #include<cstring>
 4 #define N 200010
 5 #define rg register
 6 using namespace std;
 7 int n,m,l1,l2,pos,a[N],top;
 8 char s[N],s1[N];
 9 inline int read(){
10     int k=0; char c=getchar();
11     while(c<'0'||c>'9')c=getchar();
12     while('0'<=c&&c<='9')k=k*10+c-'0',c=getchar();
13     return k;
14 }
15 inline void work(bool type){
16     if(type==0){
17         putchar('R');
18         for(rg int i=pos;i<=n;i++) putchar(s[i]);
19         putchar('C');
20         int tmp=0;
21         for(rg int i=1;i<pos;i++) tmp=tmp*26+s[i]-'A'+1;
22         printf("%d\n",tmp);
23     }
24     else{
25         int pos2=pos;
26         while(s[pos2]>='0'&&s[pos2]<='9') pos2++; pos2++;
27         int t1=0,t2=0;
28         for(rg int i=pos2;i<=n;i++)t1=t1*10+s[i]-'0';
29         top=0;
30         while(t1){
31             a[++top]=t1%26;
32             t1/=26;
33         }
34         for(rg int i=1;i<=top-1;i++) if(a[i]<=0)a[i+1]--,a[i]+=26;
35         while(a[top]<=0) top--;
36         for(rg int i=top;i;i--) printf("%c",(char)(a[i]+'A'-1));
37         for(rg int i=pos;i<pos2-1;i++) putchar(s[i]);
38         puts("");
39     }
40 }
41 int main(){
42     m=read();
43     while(m--){
44         scanf("%s",s+1);
45         n=strlen(s+1);
46         pos=1; bool type=0;
47         while(s[pos]>='A'&&s[pos]<='Z')pos++;
48         for(rg int i=pos;i<=n;i++) if(s[i]>='A'&&s[i]<='Z'){
49             type=1; break;
50         }
51         work(type);
52     }
53     return 0;
54 }
View Code

 

posted @ 2018-05-17 19:18  Driver_Lao  阅读(224)  评论(0编辑  收藏  举报