UVA 401-Palindromes
2015-08-20 10:47
471 查看
水题细节也很重要啊。。。
In addition, after each output line, you must print an empty line.
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
typedef long long ll;
using namespace std;
char const *ch = "AEHIJLMOSTUVWXYZ12358";
char const *re = "A3HILJMO2TUVWXY51SEZ8";
bool ispalindrome(string s)
{ int len=s.size();
for(int i=0;i<len/2;i++)
if(s[i]!=s[len-i-1]) return false;
return true;
}
bool ismirror(string s)
{ int len=s.size();
int table_len = strlen(ch);
int i,j;
if(len == 1)
{
for( j=0; j<table_len; j++)
{
if(ch[j] == s[0])
break;
}
if(j == 21 || re[j] != s[0])
return 0;
}
else
{ for(i=0; i<len/2; i++)
{
for(j=0; j<table_len; j++)
{
if(ch[j] == s[i])
break;
}
if(j == 21 || re[j] != s[len-i-1])
return 0;
}
return 1;
}
}
using namespace std;
int main()
{ string s;
while(cin>>s)
{
if(ispalindrome(s))
{if(ismirror(s)) {cout<<s<<" -- is a mirrored palindrome.\n"<<endl;continue;}
else {cout<<s<<" -- is a regular palindrome.\n"<<endl;continue;}}
else {
if(ismirror(s)) {cout<<s<<" -- is a mirrored string.\n"<<endl;continue;}
else {cout<<s<<" -- is not a palindrome.\n"<<endl;continue;}
}
}
return 0;
}
In addition, after each output line, you must print an empty line.
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
typedef long long ll;
using namespace std;
char const *ch = "AEHIJLMOSTUVWXYZ12358";
char const *re = "A3HILJMO2TUVWXY51SEZ8";
bool ispalindrome(string s)
{ int len=s.size();
for(int i=0;i<len/2;i++)
if(s[i]!=s[len-i-1]) return false;
return true;
}
bool ismirror(string s)
{ int len=s.size();
int table_len = strlen(ch);
int i,j;
if(len == 1)
{
for( j=0; j<table_len; j++)
{
if(ch[j] == s[0])
break;
}
if(j == 21 || re[j] != s[0])
return 0;
}
else
{ for(i=0; i<len/2; i++)
{
for(j=0; j<table_len; j++)
{
if(ch[j] == s[i])
break;
}
if(j == 21 || re[j] != s[len-i-1])
return 0;
}
return 1;
}
}
using namespace std;
int main()
{ string s;
while(cin>>s)
{
if(ispalindrome(s))
{if(ismirror(s)) {cout<<s<<" -- is a mirrored palindrome.\n"<<endl;continue;}
else {cout<<s<<" -- is a regular palindrome.\n"<<endl;continue;}}
else {
if(ismirror(s)) {cout<<s<<" -- is a mirrored string.\n"<<endl;continue;}
else {cout<<s<<" -- is not a palindrome.\n"<<endl;continue;}
}
}
return 0;
}
相关文章推荐
- 老板会喜欢那种程序员
- C#模拟PrtScn实现截屏预备知识--剪贴板操作
- 数据结构——堆
- 支付宝集成问题小结
- Andorid解决HorzintalListView和ScrollView冲突问题
- Tomcat中采用HTTPS访问
- C#模拟PrtScn实现截屏预备知识--剪贴板操作
- lightoj1030(期望dp)
- python基础语法
- Mysql5.6主从复制-基于binlog
- ios 清理缓存
- 循环中异常处理机制
- 杭电1020Encoding
- 8天学通MongoDB——第一天 基础入门
- iOS 的几种模式
- POJ2635----The Embarrassed Cryptographer
- C# ContentType类型汇总
- CentOS 安装过程中设置网络的方法
- HDU3405-World Islands
- Ubuntu下mysql忘记root密码