[算法练习] UVA-401-Palindromes
UVA Online Judge 题目401 Palindromes 回文串
问题描述:
回文串(Palindromes)就是正着读和反着读完全一样的字符串,例如"ABCDEDCBA"。
镜像串(Mirrored string)有些类似回文串,字符'3'的镜像可以看成是'E',字符'A'本身就是对称的所以它的镜像字符还是'A'。我们把像"3AIAE"这样的字符串看做镜像串。
镜像回文串(Mirrored palindrome)是符合上面两个条件的字符串,比如"ATOYOTA"。‘A’、‘T’、‘O’、‘Y’几个字符的镜像字符都是其自身。
详细的字符与镜像字符对应表如下:
| Character | Reverse | Character | Reverse | Character | Reverse |
| A | A | M | M | Y | Y |
| B | N | Z | 5 | ||
| C | O | O | 1 | 1 | |
| D | P | 2 | S | ||
| E | 3 | Q | 3 | E | |
| F | R | 4 | |||
| G | S | 2 | 5 | Z | |
| H | H | T | T | 6 | |
| I | I | U | U | 7 | |
| J | L | V | V | 8 | 8 |
| K | W | W | 9 | ||
| L | J | X | X |
注意:数字0被看做和字母O相同,并且输入中只包含有字母O。
输入格式:
每行为一个需要判断的字符串,读取到文件结束符后结束。
输出格式:
针对每一行输入,你需要判断其字符串类型并输出原字符串加上语句,见下表:
| STRING | CRITERIA |
| " -- is not a palindrome." | 既不是回文也不是镜像串 |
| " -- is a regular palindrome." | 普通回文串 |
| " -- is a mirrored string." | 镜像串 |
| " -- is a mirrored palindrome." | 镜像回文串 |
注意:每行语句之间有一个空行,也就是说需要在字符串后面写上“\n\n”,这个地方WA了一次。。太坑爹了。
示例输入:
NOTAPALINDROME
ISAPALINILAPASI
2A3MEAS
ATOYOTA
示例输出:
NOTAPALINDROME -- is not a palindrome. ISAPALINILAPASI -- is a regular palindrome. 2A3MEAS -- is a mirrored string. ATOYOTA -- is a mirrored palindrome.
代码:(没注意输出格式WA一次。。)
/*
Problem : UVA Online Judge - 401 Palindromes
Date:2014-04-03
Author:Leroy
*/ #include <stdio.h>
#include <string.h> char ch[] = "AEHIJLMOSTUVWXYZ12358";
char chRe[] = "A3HILJMO2TUVWXY51SEZ8"; int hasRe(char c)
{
int has = ;
for (int i = ; i < ; i++)
{
if (ch[i] == c)
has = ;
}
return has;
} char getRe(char c)
{
for (int i = ; i < ; i++)
{
if (ch[i] == c)
return chRe[i];
}
} int is_P(char* str, int n)
{
int i;
for (i = ; i < n / ; i++)
{
if (str[i] != str[n - i - ])
return ;
}
return ;
} int is_M(char* str, int n)
{
if (n == )
{
if (hasRe(str[]))
{
return ;
}
else
{
return ;
}
} for (int i = ; i < n / ; i++)
{
if (hasRe(str[i]))
{
char t = getRe(str[i]);
if (t != str[n - i - ])
{
return ;
}
}
else
{
return ;
}
} if (n % != )
{
int x = n / ;
if (hasRe(str[x]))
{
return ;
}
else
{
return ;
}
} return ;
} int main(){
char str[];
while (gets(str) != NULL)
{
int len = strlen(str);
if (len == )
break;
int isMirro = , isPalin = ;
int i = ; isPalin = is_P(str, len);
isMirro = is_M(str, len); if (isPalin == ){
if (isMirro == )
printf("%s -- is not a palindrome.\n\n", str);
else
printf("%s -- is a mirrored string.\n\n", str);
}
else
{
if (isMirro == )
printf("%s -- is a regular palindrome.\n\n", str);
else
printf("%s -- is a mirrored palindrome.\n\n", str);
} }
}
[算法练习] UVA-401-Palindromes的更多相关文章
- uva 401.Palindromes
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- UVa 401 - Palindromes 解题报告 - C语言
1.题目大意 输入字符串,判断其是否为回文串或镜像串.其中,输入的字符串中不含0,且全为合法字符.以下为所有的合法字符及其镜像: 2.思路 (1)考虑使用常量数组而不是if或switch来实现对镜像的 ...
- uva 401 Palindromes 解题报告
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVa 401 Palindromes(镜像回文字符串)
题意 给一个字符串 判定其是否为回文串和镜像串 回文串非常好推断 镜像串对于每个字符用数组保存它的镜像字符即可了 没有的就是空格 注意若字符串长度为奇数 中间那个字母必须是对称的才是镜 ...
- 【例题3-3 UVA - 401】Palindromes
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 如果一个字符没有对应的镜像,那么它对应的是一个空格. 然后注意 aba这种情况. 这种情况下b也要查一下它的镜像是不是和b一样. [ ...
- Palindromes UVA - 401
A regular palindrome is a string of numbers or letters that is the same forward as backward. For e ...
- UVA大模拟代码(白书训练计划1)UVA 401,10010,10361,537,409,10878,10815,644,10115,424,10106,465,10494
白书一:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=64609#overview 注意UVA没有PE之类的,如果PE了显示WA. UVA ...
- RMQ算法 以及UVA 11235 Frequent Values(RMQ)
RMQ算法 简单来说,RMQ算法是给定一组数据,求取区间[l,r]内的最大或最小值. 例如一组任意数据 5 6 8 1 3 11 45 78 59 66 4,求取区间(1,8) 内的最大值.数据量小 ...
- 401 Palindromes(回文词)
Palindromes A regular palindrome is a string of numbers or letters that is the same forward as ba ...
- [算法练习] UVA 10420 - List of Conquests?
UVA Online Judge 题目10420 - List of Conquests 问题描述: 题目很简单,给出一个出席宴会的人员列表,包括国籍和姓名(姓名完全没用).统计每个国家有多少人参加, ...
随机推荐
- VHDL TestBench基础(转)
TestBench的主要目标是: 实例化DUT-Design Under Test 为DUT产生激励波形 产生参考输出,并将DUT的输出与参考输出进行比较 提供测试通过或失败的指示 TestBench ...
- Unity3D细节整理:AssetBundle对应的各种格式文件的类型
我们打包AssetBundle后,Unity3D会根据文件的后缀名将文件转换为特定的类型对象存储起来,我们后期获取时需要根据这些类型取出打包的数据,这里记录下不同后缀文件打包后的类型. 文本格式 支持 ...
- C# winform 最小化到电脑右下角
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- 神经网络环境搭建,windows上安装theano和keras的流程
今天碰到有朋友问道怎么在windows下安装keras,正好我刚完成搭建,总结下过程,也算是一个教程吧,给有需要的朋友. 步骤一:安装python. 这一步没啥好说的,下载相应的python安装即可, ...
- PostgreSQL的 initdb 源代码分析之十五
继续分析: if (pwprompt || pwfilename) get_set_pwd(); 由于我启动initdb的时候,没有设置口令相关的选项,故此略过. 接下来: setup_depend( ...
- Codeforces Round #277 (Div. 2) B. OR in Matrix 贪心
B. OR in Matrix Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/486/probl ...
- 401 Palindromes(回文词)
Palindromes A regular palindrome is a string of numbers or letters that is the same forward as ba ...
- delphi TreeView修改选中的节点的颜色和背景
TreeView修改选中的节点的颜色和背景 TCustomDrawTarget = (dtControl, dtItem, dtSubItem); TCustomDrawStage = ...
- 用adb pull命令从android系统中读取文件失败的原因及解决办法
问题:使用adb pull命令从android系统中读取文件失败.显示:Permission denied 原因:是由于文件权限原因引起. 使用ls -l命令查看android系统中的 ...
- Sales_item例子
Sales_item.h #ifndef SALES_ITEM_H #define SALES_ITEM_H #include<iostream> #include<string&g ...