码迷,mamicode.com
首页 > 其他好文 > 详细

UVA 401 - Palindromes

时间:2016-03-29 12:31:07      阅读:99      评论:0      收藏:0      [点我收藏+]

标签:

题意:输入字符串,判断回文和镜像

分析:打表,比对,标志变量判断

注释:水题,注意细节,注意输出格式!!!!!!!!!!!!!!!

 1 //#define LOCAL
 2 #include"cstdio"
 3 #include"cstring"
 4 #include"cctype"
 5 using namespace std;
 6 const int maxn=100;
 7 char s1[maxn],s[]="A   3  HIL JM O   2TUVWXY51SE Z  8 ";
 8 bool pal,mir;
 9 char r(char c)
10 {
11     if(isalpha(c)) return s[c-A];
12     return s[c-0+25];
13 }
14 void print()
15 {
16     if(pal&&mir) printf("%s -- is a mirrored palindrome.\n\n",s1);
17     if(!pal&&mir) printf("%s -- is a mirrored string.\n\n",s1);
18     if(pal&&!mir) printf("%s -- is a regular palindrome.\n\n",s1);
19     if(!pal&&!mir) printf("%s -- is not a palindrome.\n\n",s1);
20 }
21 int main()
22 {
23     #ifdef LOCAL
24     freopen("in.txt","r",stdin);
25     freopen("out.txt","w",stdout);
26     #endif // LOCAL
27     while(scanf("%s",s1)!=EOF)
28     {
29         int len=strlen(s1);pal=true;mir=true;
30         for(int i=0;i<(len+1)/2;i++)
31         {
32             if(s1[i]!=s1[len-1-i]) pal=false;
33             if(r(s1[i])!=s1[len-1-i]) mir=false;
34         }
35         print();
36     }
37     return 0;
38 }

 

UVA 401 - Palindromes

标签:

原文地址:http://www.cnblogs.com/nuc-gxg/p/5332294.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!