算法竞赛入门经典第二版 回文词P49
2024-09-06 21:44:02
#include<bits/stdc++.h>
using namespace std;
char rev[]="A 3 HIL JM O 2TUVWXY51SE Z 8 ";
char *msg[]={"is not a palindrome","is a regular palindrome","is a mirrored string","is a mirrored palindrome"} ;
char aa(char a){
if(isalpha(a)) return rev[a-'A'];//判断字符ch是否为英文字母,若为英文字母,返回非0(小写字母为2,大写字母为1)。若不是字母,返回0。
else return rev[a-''+];
}
int main(){
char s[];
while(scanf("%s",s)==){
int p=,m=;
int len=strlen(s);
for(int i=;i<(len+)/;i++){
if(s[i]!=s[len--i]) p=;//回文串判断
if(aa(s[i])!=s[len--i]) m=;//镜像串判断 镜像之后,是否和右边的一样
}
printf("%s--%s.\n",s,msg[m*+p]);
} return ;
}
如果ch是大写字母,则ch-‘A’就是它在字母表中的序号,(A的序号为0,B为1)
如果ch为数字,那么ch-‘0’就是这个数值本身,' 5 ' - ' 0 ' =5;
最新文章
- php中redis的安装
- Windows Azure Service Bus (5) 主题(Topic) 使用VS2013开发Service Bus Topic
- ZOJ 1095 Humble Numbers
- Android窗口管理服务WindowManagerService对壁纸窗口(Wallpaper Window)的管理分析
- sublime实现markdown浏览器预览
- 【优秀的图片后期编辑工具】Luminar 3.1 for Mac
- 关于element-ui表格table设置header-cell-class-name样式不起作用的原因分析
- nginx中root和alias的区别
- Python从菜鸟到高手(18):类与方法的私有化
- 洛谷P2764 最小路径覆盖问题
- Delphi中封装ADO之我重学习记录
- Educational Codeforces Round 26-D. Round Subset
- 【tomcat】启动报错:Failed to initialize end point associated with ProtocolHandler [";http-apr-8080";] java.lang.Exception: Socket bind failed 和java.net.BindException: Address already in use: JVM_Bind错误解决
- svn log — 显示提交日志信息
- PHP CURL 抓取失败 自己调试
- bzoj 2406 二分+有源有汇上下界网络流可行流判定
- 一站式学习Wireshark(十):应用Wireshark显示过滤器分析特定数据流(下)
- C# - 静态类和静态构造函数
- Java 实现 RSA 非对称加密
- 9.详解引擎(InnoDB,MyISAM)的内存优化攻略?