您的位置:首页 > 其它

UVA401map和string的查找返回值

2015-07-19 20:16 429 查看
这题脑子笨,想了好久没想到怎么建立一个相互映射,最后用的map,

其实可以建立俩个字符数组,形成相互映射,来判断;

另外map查找查找不到返回.end();

string查找不到返回string::npos;

看下面代码:注释部分为map写法

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<cctype>
#include<string>
#include<map>
#define LL long long
using namespace std;
int main()
{
/*  map<char,char> c;
c['A']='A';
c['E']='3';
c['H']='H';
c['I']='I';
c['J']='L';
c['L']='J';
c['M']='M';
c['O']='O';
c['S']='2';
c['T']='T';
c['U']='U';
c['V']='V';
c['W']='W';
c['X']='X';
c['Y']='Y';
c['Z']='5';
c['1']='1';
c['2']='S';
c['3']='E';
c['5']='Z';
c['8']='8';
*/
string x="AEHIJLMOSTUVWXYZ12358";
string y="A3HILJMO2TUVWXY51SEZ8";
string s;
while(cin>>s)
{
string a=s;
reverse(a.begin(),a.end());
int temp=1;
/*  for(int i=0;i<s.length();i++)
{
if(c.find(s[i])!=c.end()&&c[s[i]]==a[i]);
else
{
temp=0;
break;
}
}*/
for(int i=0;i<s.length();i++)
{
if(x.find(s[i])!=string::npos&&y[x.find(s[i])]==a[i]);
else
{
temp=0;
break;
}
}
if(a!=s&&!temp)
cout<<s<<" -- is not a palindrome."<<endl;
if(a!=s&&temp)
cout<<s<<" -- is a mirrored string."<<endl;
if(a==s&&!temp)
cout<<s<<" -- is a regular palindrome."<<endl;
if(a==s&&temp)
cout<<s<<" -- is a mirrored palindrome."<<endl;
cout<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: