UVA401map和string的查找返回值
2015-07-19 20:16
429 查看
这题脑子笨,想了好久没想到怎么建立一个相互映射,最后用的map,
其实可以建立俩个字符数组,形成相互映射,来判断;
另外map查找查找不到返回.end();
string查找不到返回string::npos;
看下面代码:注释部分为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; }
相关文章推荐
- nginx之keepalive
- golang之flag.String
- Maven+Eclipse+Hadoop第一个WordCount
- vector使用swap释放内存
- Java程序员,你为什么要关注Scala
- SEO优化-伪静态-URLRewrite 详解
- 初步认识机房收费
- 聊天室螺旋式体系结构设计——思考过程
- openstack临时存储后端
- /etc/sudoers
- UVA529 Addition Chains (迭代+DFS)
- 关于镜像文件和虚拟光驱
- 机房收费系统——退卡
- 数据存储
- urlrewrite 地址重写
- 趣味描述之匈牙利算法
- DOM文档学习
- C语言的字符串输入输出
- linux命令,系统安全相关命令--改变文件属性与权限(chgrp,chwon,chmod)
- android colors.xml 开发必备