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

题目意思:判断一行字符串为以下四种的哪一种:A regular palindrome,A mirrored string,A mirrored palindrome 和 is not a palindrome。A regular palindrome 就是我们见得最多的普通回文字符串,正读和反读是一样的;A mirrored string 就是根据以下的一套规则,将每个character变成对应的reverse,变完之后反读起来是和原来的字符串是一样的。

比较坑爹的一个地方是,对于B、C、D、F、G、K...6、7 这些没有reverse的字符,如果字符串里有这些字符,就绝对不是mirrored string了。还有就是记得,输出每一行结果之后,还要追加一个空行!

 #include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
using namespace std; const int maxn = + ;
char s[maxn], rev[maxn];
int len, l; char test[] = {'B', 'C', 'D', 'F', 'G', 'K', 'N', 'P', 'Q', 'R', '', '', '', ''}; // 非 mirrored 的 字符
char match[] = {'E', 'J', 'L', 'S', 'Z', '', '', ''};
char match1[] = {'', 'L', 'J', '', '', 'S', 'E', 'Z'}; bool Is_palindrome()
{
for (int i = ; i <= len/; i++)
{
if (s[i] != s[len-i-])
return false;
}
return true;
} bool check()
{
for (int j = ; j < len; j++)
{
for (int i = ; i <= ; i++)
{
if (s[j] == test[i]) // 找到一个非mirrored 的 字母,就不可能是mirrored string了
return false;
}
}
return true;
} bool Is_mirrored()
{
int f;
l = ;
for (int i = ; i < len; i++)
{
f = ;
for (int j = ; j < ; j++)
{
if (s[i] == match[j])
{
rev[l++] = match1[j]; // 替换该字符的reverse
f = ;
}
}
if (!f) // reverse 与 它本身一样,例如A、I
rev[l++] = s[i];
}
for (int j = l-; j >= ; j--)
if (rev[j] != s[l-j-])
return false;
return true;
} int main()
{
while (scanf("%s", s) != EOF)
{
len = strlen(s);
  if (Is_palindrome())
  {
   if (check() && Is_mirrored())
   printf("%s -- is a mirrored palindrome.\n\n", s);
   else
   printf("%s -- is a regular palindrome.\n\n", s);
   }
   else
   {
  if (check() && Is_mirrored())
  printf("%s -- is a mirrored string.\n\n", s);
   else
  printf("%s -- is not a palindrome.\n\n", s);
  }
}
return ;
}

uva 401 Palindromes 解题报告的更多相关文章

  1. UVa 401 - Palindromes 解题报告 - C语言

    1.题目大意 输入字符串,判断其是否为回文串或镜像串.其中,输入的字符串中不含0,且全为合法字符.以下为所有的合法字符及其镜像: 2.思路 (1)考虑使用常量数组而不是if或switch来实现对镜像的 ...

  2. USACO Section1.5 Prime Palindromes 解题报告

    pprime解题报告 —— icedream61 博客园(转载请注明出处)--------------------------------------------------------------- ...

  3. USACO Section1.2 Dual Palindromes 解题报告

    dualpal解题报告 —— icedream61 博客园(转载请注明出处)-------------------------------------------------------------- ...

  4. uva 401.Palindromes

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

  5. USACO Section 1.2 Dual Palindromes 解题报告

    题目 题目描述 有一些数(如 21),在十进制时不是回文数,但在其它进制(如二进制时为 10101)时就是回文数. 编一个程序,从文件读入两个十进制数N.S.然后找出前 N 个满足大于 S 且在两种以 ...

  6. USACO Section 1.5 Prime Palindromes 解题报告

    题目 题目描述 题目就是给定一个区间[a,b]((5 <= a < b <= 100,000,000)),我们需要找到这个区间内所有既是回文串又是素数的数字. 输入样例 5 500 ...

  7. SP7586 NUMOFPAL - Number of Palindromes 解题报告

    SP7586 NUMOFPAL - Number of Palindromes 题意翻译 求一个串中包含几个回文串 输入输出格式 输入格式: The string S. 输出格式: The value ...

  8. UVa 401 Palindromes(镜像回文字符串)

     题意  给一个字符串 判定其是否为回文串和镜像串  回文串非常好推断  镜像串对于每个字符用数组保存它的镜像字符即可了  没有的就是空格 注意若字符串长度为奇数  中间那个字母必须是对称的才是镜 ...

  9. 【LeetCode】906. Super Palindromes 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 BFS解法 相似题目 参考资料 日期 题目地址:ht ...

随机推荐

  1. Visual Studio各版本下载链接

    Visual Studio 2015 企业版 链接: https://pan.baidu.com/s/1NFGyIbm2RNsuwwEU-bYicQ 提取码: m961 Visual Studio 2 ...

  2. see

    Description 问从点(0,0)能看到点(0,0)和(n,n)之间的矩形的多少个整数点,看到(x,y)代表点(0,0)和点(x,y)间没有其他整数点,如看不到(2,4)因为中间有点(1,2) ...

  3. Linux包括hash_map和hash_set的not declared问题

    当在Linux下cpp文件包括hash_map或hash_set时.会出现"'hash_map' was not declared in this scope"问题. #inclu ...

  4. Git bare repo with multiple branches

    http://stackoverflow.com/questions/9324762/git-bare-repo-with-multiple-branches Q: I want to make a ...

  5. c++ builder 版CreateAnonymousThread用法

    万一老师的<如今, Delphi 的多线程已经很易用了!>讲到了TThread.CreateAnonymousThread用法 如今我来讲在c++ builder使用 CreateAnon ...

  6. websotrom 2016.2 license Server

    license server” 输入:http://114.215.133.70:41017 仅供学习测试使用,支持正版.

  7. Active Directory的LDAP协议与DN(Distinguished Name)详解

    前言 光copy几段代码的文章没什么意思,本章上最基础的代码,主要是为了从编程方面聊LDAP和DN,其它的后面聊,一步步慢慢来吧. Active Directory编程须知 1.域控服务器: Wind ...

  8. API网关如何实现对服务下线实时感知

    上篇文章<Eureka 缓存机制>介绍了Eureka的缓存机制,相信大家对Eureka 有了进一步的了解,本文将详细介绍API网关如何实现服务下线的实时感知. 一.前言 在基于云的微服务应 ...

  9. VMware虚拟机下实现Linux与window文件夹共享

    这里说的是在VMware虚拟机下来实现在windows与Linux下共享一个文件夹. 下面来说明一下是如何实现的: 1.安装VMware.Workstation. 2.安装Fedora10. 3.完成 ...

  10. MonoTouch.Dialog简介

    新建一个Single View Application项目 添加程序集 MonoTouch.Dialog.dll引用 删除 MainStoryboard.storyboard 添加空类Task.cs ...