[算法练习] 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 问题描述: 题目很简单,给出一个出席宴会的人员列表,包括国籍和姓名(姓名完全没用).统计每个国家有多少人参加, ...
随机推荐
- CodeForces 560B Gerald is into Art
Gerald is into Art time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- ASP.Net自定义重写Http Server标头
Net中我们为了安全或其他原因起见 可能需要修改我们的标头报文等 以下方法我们通过使用HTTP Module来使用编程的方式来去除或修改它 首先我们自定义一个类CustomServerHeaderMo ...
- Contest 7.23(不知道算什么)
Problem A URAL 1181 Cutting a Painted Polygon 题目大意就是说有一个N边形,让你做N-3条边,让他们的每个三角形的三个顶点颜色都不相同. 这里有一个引理 ...
- MemCacheManager
#region Fields private AreaRepository _areaRepository = new AreaRepository(); private ICacheManager ...
- 存储过程[st_MES_RptInspectShipment]
USE [ChangHong_612]GO/****** Object: StoredProcedure [dbo].[st_MES_RptInspectShipment] Script Date: ...
- GMT、UTC、PDT 时间是什么?Linux下如何调整时区
今天碰到一个时区配置问题,如果服务器时区配置不对,很可能在使用date相关函数时会出现莫名其妙的错误,现将相关时区说明及LINUX下调整时区方法记录如下,以做备忘. GMT GMT 是 Gree ...
- 预览Cube出现没有注册类错误
用Microsoft SQL Server Management Studio预览AS上的Cube 出现如下错误. TITLE: Microsoft SQL Server Management Stu ...
- 文件映射spring 使用classpath方式加载hibernate映射文件
在改章节中,我们主要介绍文件映射的内容,自我感觉有个不错的建议和大家分享下 <!-- 批量指定到classpath下面 --> <property name="mappin ...
- C#的图片拼接
貌似很长时间没有写博客了,感觉再不写都要废了. 这段时间确实迷茫得不行,整天混混顿顿的,逃避这个逃避那个,话说已经辞职一个月了…… 这几天在学用libgdx做安卓上的游戏,感觉缺少一个图片拼接的工具, ...
- Codeforces Gym 100418A A - A+-B java高精度
A - A+-BTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.acti ...