首页 > 其他 > 详细

CF1B Spreadsheets

时间:2018-05-17 19:40:45      阅读:193      评论:0      收藏:0      [点我收藏+]

技术分享图片

【题解】

  模拟就行,类似进制转换

技术分享图片
 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

 

CF1B Spreadsheets

原文:https://www.cnblogs.com/DriverLao/p/9052744.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!