uva 401 Palindromes
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=96&page=show_problem&problem=342 题意:问一个字符串是不是回文串,是不是镜像串。镜像串的意思是。。从镜子里看还一样。。给定了一些存在镜像的字母和数字。。 思路:回文串的判断用c++的string要更容易一些。。直接reverse一下。。判断是否相等就行。。。然后需要注意的是。。如果某个字符补存在镜像那么一定不是镜像串
如果某个字符不存在镜像那么一定不是镜像串!
如果某个字符不存在镜像那么一定不是镜像串!
蠢哭惹好么。。。。
* ***********************************************
Author :111qqz
Created Time :2016年01月20日 星期三 16时00分57秒
File Name :code/uva/401.cpp
************************************************ */
1#include <cstdio>
2#include <cstring>
3#include <iostream>
4#include <algorithm>
5#include <vector>
6#include <queue>
7#include <set>
8#include <map>
9#include <string>
10#include <cmath>
11#include <cstdlib>
12#include <ctime>
13#define fst first
14#define sec second
15#define lson l,m,rt<<1
16#define rson m+1,r,rt<<1|1
17#define ms(a,x) memset(a,x,sizeof(a))
18typedef long long LL;
19#define pi pair < int ,int >
20#define MP make_pair
1using namespace std;
2const double eps = 1E-8;
3const int dx4[4]={1,0,0,-1};
4const int dy4[4]={0,-1,1,0};
5const int inf = 0x3f3f3f3f;
6string a,b;
7char tmp[1000005];
8map<char,char>mp;
9void init()
10{
11 mp.clear();
12 mp['A']='A';
mp['E']='3';
mp['3']='E';
mp['H']='H';
mp['I']='I';
mp['J']='L';
mp['L']='J';
1 mp['M']='M';
2 mp['O']='O';
3 mp['0']='O';
mp['S']='2';
mp['2']='S';
1 mp['T']='T';
2 mp['U']='U';
3 mp['V']='V';
4 mp['W']='W';
5 mp['X']='X';
6 mp['Y']='Y';
mp['Z']='5';
mp['5']='Z';
1 mp['1']='1';
2 mp['8']='8';
3}
1void solve ( bool x,bool y)
2{
3 if (!x&&!y) puts(" -- is not a palindrome.");
4 if (x&&y) puts(" -- is a mirrored palindrome.");
5 if (x&&!y) puts(" -- is a regular palindrome.");
6 if (!x&&y) puts(" -- is a mirrored string.");
7}
1bool pal(string x)
2{
3 int len = x.length();
4 for ( int i = 0 ; i< len/2 ; i++)
5 {
6 if (x[i]!=x[len-1-i]) return false;
7 }
8 return true;
9}
10bool mirr(string x,string y)
11{
12 int len = x.length();
13 for ( int i = 0 ; i < len/2 ; i++)
14 {
15 if (x[i]!=y[len-1-i]) return false;
16 }
17 return true;
18}
19int main()
20{
1 #ifndef ONLINE_JUDGE
2 freopen("code/in.txt","r",stdin);
3 #endif
4 init();
5 while (scanf("%s",tmp)!=EOF)
6 {
7 a = tmp;
8 bool ok1 = false;
9 bool ok2 = false;
10 b = a;
11 reverse(b.begin(),b.end());
12 if (a==b) ok1= true;
13 ok1 = pal(b);
14 int len = b.length();
15 int cnt = 0 ;
16 for ( int i = 0 ; i < len ; i++ )
17 {
18 if (mp.count(b[i])==1)
19 {
20 cnt++;
21 b[i] = mp[b[i]];
22 }
23 }
24 cout<<a;
25 if (a==b&&cnt==len) ok2=true;
solve(ok1,ok2);
cout<<endl;
}
1 #ifndef ONLINE_JUDGE
2 fclose(stdin);
3 #endif
4 return 0;
5}