这道题最初我是没理解清楚题意,我以为那些reverse栏空白的字母是省略了.后来在找到了更多的测试数据,发现了自己理解错了,重新读题= =,修改了下代码- -.弄了很久才AC
我的思路和别人有点不同的是,我是通过计算来得到在常量表中的位置
好吧= = 这道题本来该总结很多的,今天来忘记很多了.
#include#include #include const int maxn = 1000; int main() { #ifdef LOCAL freopen("input.txt", "r", stdin); #endif int state_m = 1, state_p = 1; int len; int a, x; //a字符在数组中位置,x数组中间位置 char s[maxn]; const char c[] = "A 3 HIL JM O 2TUVWXY51SE Z 89"; while(scanf("%s", s) != EOF) { printf("%s", s); state_m = 1; state_p = 1; len = strlen(s); x = (len + 1) / 2; for(int i = 0; i < x; i++) { a = (int)(isdigit(s[i]) ? s[i] - 23: s[i] - 65); if(s[len-1-i] == c[a]) //判断是否为mirrored { if(s[len-1-i] != s[i]) state_p = 0; } else { state_m = 0; if(s[len-1-i] != s[i]) state_p = 0; } } if(state_m && state_p) printf(" -- is a mirrored palindrome.\n\n"); else if(state_m) printf(" -- is a mirrored string.\n\n"); else if(state_p) printf(" -- is a regular palindrome.\n\n"); else printf(" -- is not a palindrome.\n\n"); memset(s, 0, sizeof(s)); } return 0; }