hdu 2100(26进制)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2100

一道水题,orz,WA了3次,坑爹啊。。。。

不说了,就是一个26进制加分,结果应该是要写成最简洁形式的。。。

View Code
 1 #include<iostream>
 2 #include<cstring>
 3 #include<cmath>
 4 const int N=222;
 5 using namespace std;
 6 char str1[N],str2[N],str[N];
 7 
 8 int main(){
 9     while(~scanf("%s",str1)){
10         scanf("%s",str2);
11         int len1=strlen(str1);
12         int len2=strlen(str2);
13         int i=0,j=0,k=0,c=0,l=0;
14         for(i=len1-1,j=len2-1;i>=0&&j>=0;i--,j--){
15             c+=str1[i]+str2[j]-'A'-'A';
16             str[k++]=c%26+'A';
17             c/=26;
18         }
19         while(i>=0){
20             c+=str1[i--]-'A';
21             str[k++]=c%26+'A';
22             c/=26;
23         }
24         while(j>=0){
25             c+=str2[j--]-'A';
26             str[k++]=c%26+'A';
27             c/=26;
28         }
29         if(c)str[k++]=c+'A';
30         l=k-1;
31         while(str[l]=='A'&&l>=1)l--;
32         for(int i=l;i>=0;i--){
33             printf("%c",str[i]);
34         }
35         printf("\n");
36     }
37     return 0;
38 }

 

posted @ 2013-03-17 10:55  ihge2k  阅读(366)  评论(0编辑  收藏  举报