HDU 2100 分类: ACM 2015-06-17 23:49 15人阅读 评论(0) 收藏

Lovekey

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 6721    Accepted Submission(s): 2186

Problem Description
XYZ-26进制数是一个每位都是大写字母的数字。 A、B、C、…、X、Y、Z 分别依次代表一个0 ~ 25 的数字,一个 n 位的26进制数转化成是10进制的规则如下

A0A1A2A3…An-1 的每一位代表的数字为a0a1a2a3…an-1 ,则该XYZ-26进制数的10进制值就为



m = a0 * 26^(n-1) + a1 * 26^(n-2) + … + an-3* 26^2 + an-2*26 + an-1



一天vivi忽然玩起了浪漫,要躲在学校的一个教室,让枫冰叶子去找,当然,她也知道枫冰叶子可不是路痴,于是找到了XYZ的小虾和水域浪子帮忙,他们会在vivi藏的教室的门口,分别写上一个XYZ-26进制数,分别为 a 和 b,并且在门锁上设置了密码。显然,只有找到密码才能打开锁,顺利进入教室。这组密码被XYZ的成员称为lovekey。庆幸的是,枫冰叶子知道lovekey是 a的10进制值与b的10进制值的和的XYZ-26进制形式。当然小虾和水域浪子也不想难为枫冰叶子,所以a 和 b 的位数都不会超过200位。

例如第一组测试数据

a = 0 * 26^5+0* 26^4+ 0* 26^3+ 0 *26^2 + 3*26 + 7 = 85

b = 1*26^2 + 2*26 + 4 = 732

则 a + b = 817 = BFL
 
Input
题目有多组测试数据。

每组测试数据包含两个值均为的XYZ-26进制数,每个数字的每位只包含大写字母,并且每个数字不超过200位。
 
Output
输出XYZ的lovekey,每组输出占一行。
 
Sample Input
AAAADH BCE
DRW UHD
D AAAAA
 
Sample Output
BFL
XYZ
D
 

#include<queue>

#include<math.h>

#include<stdio.h>

#include<string.h>

#include<iostream>

#include<algorithm>

using namespace std;

#define N 215

char a[N],b[N],c[N];

void reverse(char a[])

{

    int len=strlen(a);

    for(int i=0;i<len/2;i++)

    {

        swap(a[i],a[len-i-1]);

    }

}

int main()

{

    while(~scanf("%s%s",a,b))

    {



        int len_a=strlen(a);

        int len_b=strlen(b);

        reverse(a);

        reverse(b);

        int jin=0;

        for(int i=0;i<max(len_a,len_b);i++)

        {

//            cout<<b[i]<<endl;

            if(a[i]=='\0')

            {

//                printf("aaaaajin=%d\n",jin);

                if(jin)

                {

                    c[i]=b[i]-'A'+1;

                    jin=0;

                    if(c[i]>=26)

                    {

                        if(i==max(len_a,len_b)-1)

                        {

                            c[i]=c[i]-26+'A';

                            c[i+1]='B';

                            c[i+2]=0;

                        }

                        else

                        {

                            c[i]=c[i]-26+'A';

                            jin=1;

                        }

                    }

                    else

                    {

                        c[i]=c[i]+'A';

                    }

                }

                else

                {

                    c[i]=b[i];

                    jin=0;

                }



            }

            else if(b[i]=='\0')

            {

//                printf("bbbbbjin=%d\n",jin);

                if(jin)

                {

                    c[i]=a[i]-'A'+1;

                    jin=0;

                    if(c[i]>=26)

                    {

                        if(i==max(len_a,len_b)-1)

                        {

                            c[i]=c[i]-26+'A';

                            c[i+1]='B';

                            c[i+2]=0;

                        }

                        else

                        {

                            c[i]=c[i]-26+'A';

                            jin=1;

                        }

                    }

                    else

                    {

                        c[i]=c[i]+'A';

                    }

                }

                else

                {

                    c[i]=a[i];

                    jin=0;

                }

            }

//            printf("%c %c %c\n",a[i],b[i],jin);

            else {



//            printf("%c %c\n",a[i],b[i]);

            c[i]=a[i]+b[i]+jin-'A'*2;

//            printf(" *  %d \n",c[i]);

            jin=0;

            if(c[i]>=26)

            {

                if(i==max(len_a,len_b)-1)

                {

                    c[i]=c[i]-26+'A';

                    c[i+1]='B';

                    c[i+2]=0;

                }

                else

                {

                    c[i]=c[i]-26+'A';

                    jin=1;

//                    printf("jin=%d",jin);

                }

            }

            else

                c[i]=c[i]+'A';

//            printf(" #  %d %c\n",c[i],c[i]);

        }



        }



        for(int i=strlen(c)-1;i>0;i--)

        {

            if(c[i]=='A')

                c[i]='\0';

            else

            {

                break;

            }

        }

        reverse(c);



        cout<<c<<endl;

        memset(a,0,sizeof(a));

        memset(b,0,sizeof(b));

        memset(c,0,sizeof(c));



    }

    return 0;

}

版权声明:本文为博主原创文章,未经博主允许不得转载。

上一篇:Uniform Generator 分类: HDU 2015-06-19 23:26 11人阅读 评论(0) 收藏


下一篇:HDU 1532 Drainage Ditches 分类: Brush Mode 2014-07-31 10:38 82人阅读 评论(0) 收藏