LeeBlog

导航

HDU 2100 Lovekey

这是一大数题,直接套模板,其实跟十进制差不多,不过把对10取余改成对26取余就行了,水过

#include<stdio.h>
#include<string.h>
#define max 250
int num[max];
char str1[max],str2[max];
void cal(  )
{
     memset( num,0,sizeof( num ) );
     int len1 = strlen( str1 ),len2 = strlen( str2 );
     for( int i = 0; i < ( len1 > len2 ? len1 : len2 ); ++i )//转换成ASCII码
          str1[i] -= 'A',str2[i] -= 'A';
     for( int p = 0, q = len1 - 1; p < q; ++p , --q ) //逆序
     {
          char c = str1[q];
          str1[q] = str1[p];
          str1[p] = c;
      }
     for( int p = 0, q = len2 - 1; p < q; ++p,--q)
     {
          char c = str2[q];
          str2[q] = str2[p];
          str2[p] = c;
      }
      for( int i = 0,c = 0; i < ( len1 > len2 ? len1 : len2 ) || c; ++i )//相加 进位
      {
           if( i < len1 )
               c += str1[i];
           if( i < len2 )
               c += str2[i];
           num[i] = c % 26;//不同的地方1
           c /= 26;//不同的地方2
       }
 }
int main( )
{
    while( scanf( "%s%s",str1,str2 ) != EOF )
    {
           cal(  );
           int n = max;
           while( !num[--n] );
           for( ; n >= 0; --n )
                printf( "%c",num[n] + 'A' );//不同的地方3
           puts( "" );
           }
    return 0;
}

posted on 2011-04-09 17:51  LeeBlog  阅读(241)  评论(0编辑  收藏  举报