UVA 401 Palindromes String 第一题

传送门  http://openoj.awaysoft.com:8080/judge/contest/view.action?cid=326#problem/A

题意是这样的 判断回文或者是是否是镜子的字符串(左右对称)

#include<stdio.h>
#include<string.h>
char str[100];
char m_left[200]= {"AMYZO12E3S5HTIUJV8WLX"};  //对称的字符序列
char m_right[200]={"AMY5O1S3E2ZHTIULV8WJX"};
int palindrome(int len)   //判断回文
{
    int i=len-1,j;
    for(j=0;j<=i;j++,i--)
    {
      if(str[i]!=str[j])break;                     
    }   
    if(i<j)return 1;
    return 0;
}            
int mirror(int len)   判断对称的字符
{
    char *pos_left,*pos_right;
    int edge=strlen(m_left),i=len-1,j;
    for(j=0;j<=i;j++,i--)
    {
       pos_left=strchr(m_left,str[j]);                    
       pos_right=strchr(m_right,str[i]);
       if(pos_left==NULL||pos_right==NULL)break;                    
       else {
              if( (pos_left-m_left)!=(pos_right-m_right) )break; 
            }
    }
    if(i<j)return 1;
    return 0;
    
}


int main()
{


    int judge_p,judge_m;
    while(scanf("%s",str)!=EOF)
    {
        judge_p=judge_m=0;                       
        int len=strlen(str);                     
        judge_p=palindrome(len);
        judge_m=mirror(len);
        if((judge_p==0)&& (judge_m==0))printf("%s -- is not a palindrome.\n\n",str);
        if((judge_p==1)&& (judge_m==0))printf("%s -- is a regular palindrome.\n\n",str);
        if((judge_p==0)&& (judge_m==1))printf("%s -- is a mirrored string.\n\n",str);
        if((judge_p==1)&& (judge_m==1))printf("%s -- is a mirrored palindrome.\n\n",str);
    }     
} 




你可能感兴趣的:(UVA 401 Palindromes String 第一题)