401

刘汝佳分类第一题,用map处理的
刚看了看别人怎么处理的,发现了一种映不错的射方法:
char m[40] = "A###3##HIL#JM#O###2TUVWXY5#1SE#Z##8#";
大概就这样
401
1 #include <iostream>
2 #include <map>
3 #include <cstdio>
4 #include <cstring>
5 #include <string>
6 #include <cmath>
7 using namespace std;
8
9 char s[200];
10 char s1[14] = "AHIMOTUVWXY18";
11 char s2[9] = "EJZS25L3";
12 int tag, len;
13
14 map <char, int> table1;
15 map <char,char> table2;
16
17 int main()
18 {
19 //freopen("a.txt", "r", stdin);
20 for(int i = 0;i < 13;i++)
21 {
22 table1[s1[i]] = 1;
23 }
24 for(int i = 0;i < 8;i++)
25 {
26 table2[s2[i]] = s2[7-i];
27 //printf("%c ", table2[s2[i]]);
28 }
29 while(gets(s))
30 {
31 printf("%s -- ", s);
32 len = strlen(s);
33 tag = 1;
34 for(int i = 0;i < len;i++)
35 {
36 if(table1[s[i]] == 0)
37 {
38 tag = 0;
39 break;
40 }
41 if(s[i]!=s[len-1-i])
42 {
43 tag = 0;
44 break;
45 }
46 }
47 if(tag == 1)
48 {
49 printf("is a mirrored palindrome.\n\n");
50 continue;
51 }
52 tag = 1;
53 for(int i = 0;i < len;i++)
54 {
55 if(table2[s[i]] == s[len-1-i]||(table1[s[i]] == 1&&s[i] == s[len-1-i]))
56 {
57 continue;
58 }
59 else
60 {
61 tag = 0;
62 break;
63 }
64 }
65 if(tag == 1)
66 {
67 printf("is a mirrored string.\n\n");
68 continue;
69 }
70 tag = 1;
71 for(int i = 0;i < len;i++)
72 {
73 if(s[i]!=s[len-1-i])
74 {
75 tag = 0;
76 break;
77 }
78 }
79 if(tag == 1)
80 {
81 printf("is a regular palindrome.\n\n");
82 continue;
83 }
84 else printf("is not a palindrome.\n\n");
85 }
86 return 0;
87 }
posted @ 2011-05-12 00:05  KOKO's  阅读(179)  评论(0编辑  收藏  举报