(1)镜面、回文字符串判定,简单的字符串问题,uva上的第一交,AC。
(2)开数组记录较为凌乱的数据,常用的手段。
具体代码:
View Code
#include<stdio.h> #include<string.h> char map1[]="ABCD EFG HIJK LMN PQR STUVWXYZ1234 567 89 "; char map2[]="A BCD3 FGHIL KJM N PQR2TUVWXY51SE 4Z 678 9" ; char str[100]; int cmp1(int x, int y) { return str[x]==str[y]; } int find(char *ch, char c) { for(int i=0;ch[i]!=0;i++) if(ch[i]==c) return i; return -1; } int cmp2(int x, int y) { int a, b; if((a=='0'||b=='O')&&(a=='0'||b=='O')) return 1; a=find(map1, str[x]); b=find(map2, str[y]); return a==b; } int main() { int i, j; while(scanf("%s", str)!=EOF) { int n=strlen(str); int a, b; a=b=1; for(i=n/2;i<n;i++) if(!cmp1(n-1-i, i)) {a=0; break;} for(i=n/2;i<n;i++) if(!cmp2(n-1-i, i)) {b=0; break;} printf("%s -- ", str); if(a&&b) printf("is a mirrored palindrome.\n"); else if(!a&&b) printf("is a mirrored string.\n"); else if(a&&!b) printf("is a regular palindrome.\n"); else printf("is not a palindrome.\n"); printf("\n"); } return 0; }
