UVa 401 - Palindromes

哇靠,拼到现在也不容易了,这道水题wa了3遍才过,这都是教训啊!!!  不过有长进的是用上了上次的教训:常量数组的使用。

本题出的问题主要有:对数组b进行赋值时没有对其结束位置加'\0',习惯不好 ; 对镜像串的理解出现差错;  审题时没有注意每组数据之后有一个空格,因此wa了一次,太不值了!。

继续来吧!!!

#include <stdio.h>
#include <string.h>
#include <ctype.h>
char d1[]="AEHIJLMOSTUVWXYZ12358";
char d2[]="A3HILJMO2TUVWXY51SEZ8";
int main()
{
    int i,j,k,n,r,s,t,hui,jing;
    char a[10000],b[10000];
    while( scanf("%s",a)!=EOF )
    {
        t=0;   hui=0;  jing=0;
        n=strlen(a);
        for(i=n-1; i>=0; i--)
           {b[t]=a[i]; t++;}
         b[t]='\0';
        if( strcmp(a,b)==0 )
            hui=1;
         else
             hui=0;
        for(i=0; i<n; i++)
        {
            r=0;
            for(j=0; j<22; j++)
            {
                if( b[i] == d2[j] )
                {
                    r=1;
                    b[i]=d1[j];
                    break;
                }
            }


            if(r==0)
                b[i]='a';
        }


        if( strcmp(a,b)==0 )
             jing=1;
        else
             jing=0;


          if(hui==0 && jing==0)
               printf("%s -- is not a palindrome.\n",a);
          else if(hui==1 && jing==0)
               printf("%s -- is a regular palindrome.\n",a);
         else if(hui==0 && jing==1)
               printf("%s -- is a mirrored string.\n",a);
         else if(hui==1 && jing== 1)
                printf("%s -- is a mirrored palindrome.\n",a);


          printf("\n");
    }


    return 0;
}

你可能感兴趣的:(UVa 401 - Palindromes)