题目链接: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. SQLServer 跟踪 扩展事件(Extended Events) 专家

    http://blog.csdn.net/kk185800961/article/details/49725903

  2. ActiveX控件打包成Cab置于网页中自动下载安装 [转]

    http://blog.sina.com.cn/s/blog_520c32270100nopj.html 做过ActiveX控件的朋友都知道,要想把自己做的ActiveX控件功能放在自己的网页上使用, ...

  3. ARC forbids Objective-C objects in structs or unions

    解决方法有二种: 1.在出错的地方加入__unsafe_unretained 2.关闭系统ARC.1.点击project   2.点击Build Setting    3.找到其以下的Objetive ...

  4. 使用 rman duplicate from active database 搭建dataguard 手记--系列二

    run { allocate channel prmy1 type disk; allocate channel prmy2 type disk; allocate channel prmy3 typ ...

  5. bootstrap3分页

    <%@ page language="java" import="java.util.*" pageEncoding="utf-8"% ...

  6. js eval 解析字符串

    //带变量的字符串var str = 'var a=1; var b=2;'; eval(str); alert(a+b);//结果 3: //数组字符串var arrStr = "[1,2 ...

  7. PJSIP 调用的GUID库

    PJSIP库产生随机序列串用到GUID库,针对不同的平台使用的方式不同:Windows平台下使用的是Windows系统API CoCreateGuid,在方法 pj_generate_unique_s ...

  8. Ubuntu下安装libsvm

    在安装LibSVM前需要先装 python 和 gnuplot linux 一般都自带了python2.7,所以python的安装不再赘述 在 ubuntu 下安装 gnuplot 不能直接 sudo ...

  9. Java面向对象基础三

    1.函数的重载 2.构造函数的作用 (构造函数能够重载) 1.函数名必须和类名同样 2.没有返回值 3.使用 New 来调用构造函数 4.假设类中没有构造函数,编译器会自己主动帮忙载入一个參数为空.方 ...

  10. 如何在微信小程序中使用字体图标

    微信小程序中,在image标签里,可以在src中引用本地文件,但是background设置背景图或者使用字体图标的时候,却不能引用本地文件,只能用url地址的图片或字体,或者使用base64编码后的格 ...