Root :: Problem Set Volumes :: Volume IV
401 - Palindromes 回文词
我头一回在UVa上写题啊,不知道怎么迅速查询题目。暂时先用这样的格式来标记题目吧。
用字符常量数组来标记镜面字母比较方便啊,这一题提交了4次~ -.- 2次编译错误。 UVa还真是娇气啊。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string.h>
using namespace std;
#define LEN 25
char s[LEN];
char self[]="123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char rev[]="1SE*Z**8********A***3**HIL*JM*O***2TUVWXY5";
int main(){
#ifndef ONLINE_JUDGE
freopen("401in.txt","r",stdin);
#endif
bool pali_flag,mirror_flag;
int i,j;
while (scanf("%s",s)!=EOF){
pali_flag=true;
mirror_flag=true;
for (i=0,j=strlen(s)-1;i<=j;i++,j--){
if (!pali_flag&&!mirror_flag)
break;
if (s[i]!=s[j])
pali_flag=false;
if (self[s[i]-49]!=rev[s[j]-49])
mirror_flag=false;
}
if (!pali_flag&&!mirror_flag)
printf("%s -- is not a palindrome.\n",s);
else if (pali_flag&&!mirror_flag)
printf("%s -- is a regular palindrome.\n",s);
else if (!pali_flag&&mirror_flag)
printf("%s -- is a mirrored string.\n",s);
else if (pali_flag&&mirror_flag)
printf("%s -- is a mirrored palindrome.\n",s);
cout<<endl;
}
return 0;
}