https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=96&page=show_problem&problem=342
题目:
1. 回文数: 一串由字母和数字组成的字符串,正着读和逆着读是相同的;例如"ABCDEDCBA";
2. 镜像数:一串由字母和数字组成的字符串,当每个字符都改成它的逆字符,逆着读与原来字符串相同;
3. 镜像回文数:符合回文数和镜像数的特点;
所有有效字符的逆字符:
注意:零'0' 不属于有效字符;
输入:
多行字符串,每一行包括1-20个有效字符;
输出:
对于每一行字符串,先打印字符串然后再打印判断结果;
每打印一行结果,然后打印一个空行;
Sample Input
NOTAPALINDROME
ISAPALINILAPASI
2A3MEAS ATOYOTA
Sample Output
NOTAPALINDROME -- is not a palindrome.
ISAPALINILAPASI -- is a regular palindrome.
2A3MEAS -- is a mirrored string.
ATOYOTA -- is a mirrored palindrome.
思路分析:
分别判断字符串是否为回文字符串和镜像字符串;
char aa[4][40] 表示4种打印结果;
char bb[40] 记录有效字符的逆字符,其中不存在逆字符的记为'0';
回文字符串: 对于字符串s,存在s[i]=s[len-i-1];
镜像字符串:对于字符串s,如果存在不存在逆字符的字符,则一定不是镜像字符串; 将字符串s中字符均换成逆字符,然后再判断逆着读是否与原来字符串相同;
代码:
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;char aa[4][40]={" -- is not a palindrome."," -- is a regular palindrome."," -- is a mirrored string."," -- is a mirrored palindrome."};char bb[40]={'A','0','0','0','3','0','0','H','I','L','0','J','M','0','O',
'0','0','0','2','T','U','V','W','X','Y','5','1','S','E','0','Z','0','0','8','0'};bool palindome(string);
bool mirrored(string);int main()
{// freopen("input.txt","r",stdin);string s;bool f1,f2;int i;while(cin>>s){f1=palindome(s);f2=mirrored(s);if(!f1&&(!f2))cout<<s<<aa[0]<<endl;else if(f1&&!f2)cout<<s<<aa[1]<<endl;else if(!f1&&f2)cout<<s<<aa[2]<<endl;elsecout<<s<<aa[3]<<endl;cout<<endl;}return 0;}bool palindome(string s)
{int i,len;len=s.length();for(i=0;i<len/2;i++)if(s[i]!=s[len-i-1])return false;return true;}bool mirrored(string s)
{int i,len,j=0;string s1;len=s.length();for(i=0;i<s.length();i++){ if(s[i]>='A'&&s[i]<='Z'){if(bb[s[i]-'A']=='0')return false;s1[i]=bb[s[i]-'A'];}else{if(bb[s[i]-'0'+25]=='0')return false;s1[i]=bb[s[i]-'0'+25];}}for(j=0;j<s.length();j++)if(s[j]!=s1[--i])return false;return true;
}

  

转载于:https://www.cnblogs.com/aiheshan/p/8854254.html

UVa 401 - Palindromes相关推荐

  1. uva 401.Palindromes

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  2. UVaOJ 401 Palindromes

    原题: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=6&page ...

  3. 【鬼畜】UVA - 401每日一题·猛男就是要暴力打表

    管他什么rev数组,msg数组简化代码 #define _CRT_SECURE_NO_WARNINGS #include <cmath> #include <iostream> ...

  4. 紫书《算法竞赛入门经典》

    紫书<算法竞赛入门经典>题目一览 第3章 数组和字符串(例题) UVA 272 TEX Quotes UVA 10082 WERTYU UVA 401 Palindromes UVA 34 ...

  5. SUPERBIN技术周刊第6期

    本技术周刊是以周为单位作为里程碑,记录一个程序员视角下的所见,所学,所想.兴趣领域包括:数学,算法,图形,图像,音视频,AI,游戏,软件开发技术,操作系统,开源,以及生活杂记等."不积跬步, ...

  6. UVA401 ​​​​​​​Palindromes【字符串】

    Palindromes UVA - 401 题目传送门 题目大意:给你一个字符串,判断其是回文串还是镜像串. AC代码: #include <cstdio> #include <io ...

  7. 提取了下刘汝佳推荐的题号...

    今天闲来没事上uva oj提取了下刘汝佳推荐的acm题号,原始数据如下: Volume 0. Getting Started    10055 - Hashmat the Brave Warrior ...

  8. 《算法竞赛入门经典》Chap3

    <算法竞赛入门经典(第二版)>第三章 思考题 题目1 必要的存储量 题目2 统计字符1的个数 示例程序 程序3-1 逆序输出 程序3-2 开灯问题 程序3-3 蛇形填数 程序3-4 竖式问 ...

  9. 初学者acm的练习题指南

    上机练习题参考题 忘了在哪找的啦~~希望对大家有帮助呦 <!--[if !supportLists]-->1.    <!--[endif]-->Programming Bas ...

最新文章

  1. yum源的超级简单配置
  2. 迭代器报“vector iterators incompatible”错的几种可能
  3. linux编译项目的命令,Linux用make指令编译进度条程序
  4. 使用SharePoint Server 2007搜索对象模型编程创建搜索查询
  5. activity的启动窗口
  6. Algs4-2.1.17动画-插入排序
  7. python的序列化是什么意思_python 什么是对象序列化
  8. 用jquery + iframe實現iframe子頁面加載完前的緩沖效果
  9. ICLR2019 论文清单
  10. django-验证码
  11. 优秀PPT 设计的十大秘诀
  12. 关于网站速度优化的一点建议
  13. hp 交换机远程连接_Hp服务器 iLO3 使用方法
  14. dym 微服务 快速开发框架
  15. 30行js爬取顶点全网任意小说
  16. 游戏:杀戮尖塔(Slay the spire)mod--拉格朗·月
  17. 使用Telnet 命令行发信
  18. 做外贸十大不能接的订单!
  19. 马来西亚吉隆坡召开的2010OpenWebAsia大会
  20. Windows XP 源代码在线泄露

热门文章

  1. centos中安装、升级git
  2. Hadoop HBase
  3. Android基础知识点的整理3
  4. 一个双线程下同一时候操作指针变量导致野指针出现的问题总结
  5. Tabs Outliner(标签系统)
  6. MaskedEdit控件
  7. ╭☆难以割舍^_^就是牵挂☆╮
  8. 数百万设备受新型 BrakTooth 蓝牙漏洞影响,并非所有厂商均修复
  9. 美国太空部队加入美国情报系统,以确保太空的安全
  10. HTML如何设置音频播放器控件的大小