uva 401 Palindromes
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=96&page=show_problem&problem=342 题意:问一个字符串是不是回文串,是不是镜像串。镜像串的意思是。。从镜子里看还一样。。给定了一些存在镜像的字母和数字。。 思路:回文串的判断用c++的string要更容易一些。。直接reverse一下。。判断是否相等就行。。。然后需要注意的是。。如果某个字符补存在镜像那么一定不是镜像串
如果某个字符不存在镜像那么一定不是镜像串!
如果某个字符不存在镜像那么一定不是镜像串!
蠢哭惹好么。。。。
1* ***********************************************
2Author :111qqz
3Created Time :2016年01月20日 星期三 16时00分57秒
4File Name :code/uva/401.cpp
5************************************************ */
6
7#include <cstdio>
8#include <cstring>
9#include <iostream>
10#include <algorithm>
11#include <vector>
12#include <queue>
13#include <set>
14#include <map>
15#include <string>
16#include <cmath>
17#include <cstdlib>
18#include <ctime>
19#define fst first
20#define sec second
21#define lson l,m,rt<<1
22#define rson m+1,r,rt<<1|1
23#define ms(a,x) memset(a,x,sizeof(a))
24typedef long long LL;
25#define pi pair < int ,int >
26#define MP make_pair
27
28using namespace std;
29const double eps = 1E-8;
30const int dx4[4]={1,0,0,-1};
31const int dy4[4]={0,-1,1,0};
32const int inf = 0x3f3f3f3f;
33string a,b;
34char tmp[1000005];
35map<char,char>mp;
36void init()
37{
38 mp.clear();
39 mp['A']='A';
40
41 mp['E']='3';
42 mp['3']='E';
43
44 mp['H']='H';
45 mp['I']='I';
46
47 mp['J']='L';
48 mp['L']='J';
49
50 mp['M']='M';
51 mp['O']='O';
52 mp['0']='O';
53
54 mp['S']='2';
55 mp['2']='S';
56
57 mp['T']='T';
58 mp['U']='U';
59 mp['V']='V';
60 mp['W']='W';
61 mp['X']='X';
62 mp['Y']='Y';
63
64 mp['Z']='5';
65 mp['5']='Z';
66
67 mp['1']='1';
68 mp['8']='8';
69}
70
71void solve ( bool x,bool y)
72{
73 if (!x&&!y) puts(" -- is not a palindrome.");
74 if (x&&y) puts(" -- is a mirrored palindrome.");
75 if (x&&!y) puts(" -- is a regular palindrome.");
76 if (!x&&y) puts(" -- is a mirrored string.");
77}
78
79bool pal(string x)
80{
81 int len = x.length();
82 for ( int i = 0 ; i< len/2 ; i++)
83 {
84 if (x[i]!=x[len-1-i]) return false;
85 }
86 return true;
87}
88bool mirr(string x,string y)
89{
90 int len = x.length();
91 for ( int i = 0 ; i < len/2 ; i++)
92 {
93 if (x[i]!=y[len-1-i]) return false;
94 }
95 return true;
96}
97int main()
98{
99
100 #ifndef ONLINE_JUDGE
101 freopen("code/in.txt","r",stdin);
102 #endif
103 init();
104 while (scanf("%s",tmp)!=EOF)
105 {
106 a = tmp;
107 bool ok1 = false;
108 bool ok2 = false;
109 b = a;
110 reverse(b.begin(),b.end());
111 if (a==b) ok1= true;
112 ok1 = pal(b);
113 int len = b.length();
114 int cnt = 0 ;
115 for ( int i = 0 ; i < len ; i++ )
116 {
117 if (mp.count(b[i])==1)
118 {
119 cnt++;
120 b[i] = mp[b[i]];
121 }
122 }
123 cout<<a;
124 if (a==b&&cnt==len) ok2=true;
125
126
127 solve(ok1,ok2);
128
129 cout<<endl;
130 }
131
132 #ifndef ONLINE_JUDGE
133 fclose(stdin);
134 #endif
135 return 0;
136}