这段代码在visual studio中可以运行,但是uva的编译器每次都是complication error, 没办法 我只能各种找测试用例,自己输入进行测试,在oceaniwater的csdn博客中我找到了很多测试用例。可是在测试
123ESI -- is not a palindrome. 我的输出是
123ESI -- is a mirrored string.
还有一下几组(先写正确输出,再写我的输出)
E -- is a regular palindrome. E -- is a mirrored palindrome.
3 -- is a regular palindrome. 3 -- is a mirrored palindrome.
2 -- is a regular palindrome. 2 -- is a mirrored palindrome.
为什么......读题读错了....mirrored palindrome的标准是:在镜像变换后,整个字符反向读和变换前正向读是一样的.......
我傻了.......
让我蹲墙角去.......
附上来自别人的代码....
/** * Author: Gneveek * Data: 2011-10-2 * Descripition: UVa 401 - Palindromes */ #include <stdio.h> #include <string.h> #define MAXN 1024 char const *ch = "AEHIJLMOSTUVWXYZ12358"; char const *re = "A3HILJMO2TUVWXY51SEZ8"; int is_palindrome(char *str) { int i,len = strlen(str); for(i=0; i<len/2; i++) { if(str[i] != str[len-i-1]) return 0; } return 1; } int is_mirrored(char *str) { int table_len = strlen(ch); int i,j,len = strlen(str); if(len == 1) { for(j=0; j<table_len; j++) { if(ch[j] == str[0]) break; } if(j == 21 || re[j] != str[0]) return 0; } else if(len > 1) for(i=0; i<len/2; i++) { for(j=0; j<table_len; j++) { if(ch[j] == str[i]) break; } if(j == 21 || re[j] != str[len-i-1]) return 0; } return 1; } int main() { //freopen("C:\\in.txt","r",stdin); char str[MAXN]; while(scanf("%s",str) != EOF) { if(is_palindrome(str)) { if(is_mirrored(str)) printf("%s -- is a mirrored palindrome.\n\n",str); else printf("%s -- is a regular palindrome.\n\n",str); } else { if(is_mirrored(str)) printf("%s -- is a mirrored string.\n\n",str); else printf("%s -- is not a palindrome.\n\n",str); } } return 0; }来自zhouyan
读题...hin重要啊....
