uva 401

【白书之路】401 - Palindromes 回文串 镜像串 palindrome  A regular palindrome is a string of numbers or letters that is the same forward as backward. For example, the string "ABCDEDCBA" is a palindrome because it is the same when the stri 阅读详情
#include <stdio.h>
#include <string.h>
#define N 30
char ch[50]="AAE3HHIIJLLJMMOOS2TTUUVVWWXXYYZ5112S3E5Z88";//0、2、4为原字符
int len=strlen(ch);
int is_palindrome(char * a)
{
	int i;
	int ok=1;
	int n=strlen(a);
	for(i=0;i<= n/2;i++)
		if(a[i]!= a[n-1-i]) {ok=0;break;}  //no
	return ok;  //ok
}

int is_mirror(char* a)
{
	char s[N];
	char s2[N];
	int j,i; int flag;
	int n=strlen(a);
	for( i=0;i<n;i++)
	{
		flag=1;
		for(j=0;j<len;j+=2)
		{
			if(a[i]==ch[j])  {s[i]=ch[j+1]; flag=0; break;}
		}
		if(flag) return 0;      //元素未找到,不是
	}
	s[i]='\0';
	for(i=0;i<n;i++)
		s2[i]=s[n-1-i];
	s2[i]='\0';
	if(strcmp(a,s2)==0) return 1;
	else return 0;
}

int main()
{
//	freopen("abc.txt","r",stdin);
	char a[N];
	while (scanf("%s",a)!=EOF)
	{
		if(is_palindrome(a)&&is_mirror(a)) printf("%s -- is a mirrored palindrome.\n\n",a);
		else if(is_palindrome(a)) printf("%s -- is a regular palindrome.\n\n",a);
		else if(is_mirror(a)) printf("%s -- is a mirrored string.\n\n",a);
		else printf("%s -- is not a palindrome.\n\n",a);
	}
	return 0;
}

1、

注意:strrev 不能用

  Palindromes 

A regular palindrome is a string of numbers or letters that is the same forward as backward. For example, the string "ABCDEDCBA" is a palindrome because it is the same when the string is read from left to right as when the string is read from right to left.


A mirrored string is a string for which when each of the elements of the string is changed to its reverse (if it has a reverse) and the string is read backwards the result is the same as the original string. For example, the string "3AIAE" is a mirrored string because "A" and "I" are their own reverses, and "3" and "E" are each others' reverses.


A mirrored palindrome is a string that meets the criteria of a regular palindrome and the criteria of a mirrored string. The string "ATOYOTA" is a mirrored palindrome because if the string is read backwards, the string is the same as the original and because if each of the characters is replaced by its reverse and the result is read backwards, the result is the same as the original string. Of course, "A""T""O", and "Y" are all their own reverses.


A list of all valid characters and their reverses is as follows.


CharacterReverseCharacterReverseCharacterReverse
AAMMYY
B N Z5
C OO11
D P 2S
E3Q 3E
F R 4 
G S25Z
HHTT6 
IIUU7 
JLVV88
K WW9 
LJXX  


Note that O (zero) and 0 (the letter) are considered the same character and therefore ONLY the letter "0" is a valid character.

Input 

Input consists of strings (one per line) each of which will consist of one to twenty valid characters. There will be no invalid characters in any of the strings. Your program should read to the end of file.

Output 

For each input string, you should print the string starting in column 1 immediately followed by exactly one of the following strings.


STRINGCRITERIA
" -- is not a palindrome."if the string is not a palindrome and is not a mirrored string
" -- is a regular palindrome."if the string is a palindrome and is not a mirrored string
" -- is a mirrored string."if the string is not a palindrome and is a mirrored string
" -- is a mirrored palindrome."if the string is a palindrome and is a mirrored string

Note that the output line is to include the -'s and spacing exactly as shown in the table above and demonstrated in the Sample Output below.

In addition, after each output line, you must print an empty line.

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

『杭电1318』Palindromes Problem Description A regular palindrome is a string of numbers or letters that is the same forward as backward. For example, the string "ABCDEDCBA" is a palindrome because it is the same when the string is read from left to right as when the string is r 阅读详情

相关推荐

算典03_例题_03_HDU-1318

**判断一个字符串是否为回文串和镜像串** **回文串的意思就不用说了,正着反着相等就行了** **镜像串就是根据上面给出的表格将原串转换过去,得到的新的字符串如果和原串是逆过来相等的,它就是镜像串** **这里我觉得对应关系有很多,使用常量数组即可使其对应起来** **结果也保存在常量数组里,方便输出**

duaduac.com 527

uva401 镜像字符串

题意:输入一串字符串,判断是回文字符,还是镜像字符,还是镜像字符,还是两者都不是 首先把所有镜像字符都预处理出来,然后保存到数组里,最后暴力判断即可 #include #include #include #define rep(i, j, k) for(int i = j; i <= k; i++) #define MAXN 50 using namespace std; c

cadongllas的博客 753

python处理镜像字符串

题目:将字符串s = 'ABCabcefghbxcmvSF'装换为镜像字符串,例如a转换成z,b转换成y 首先科普一下python有两个函数ord() 跟chr() 以上截图来源菜鸟教程 有了ord函数,就可以知道每个字符对应的ASCII,当然也可以直接百度 由百度可知,小写字符a对应的十进制的ASCII是97,小写z对应的是122,26个字母刚好分成两半 a 97...

z_erduo的博客 2424

UVA - 401-Palindromes

题目链接:Palindromes UVA - 401 Palindromes Time Limit:3000MS   Memory Limit:Unknown   64bit IO Format:%lld & %llu SubmitStatus Description A regular palindrome is a

Never say never 862

UVa401 Palindromes

题目链接:https://vjudge.net/problem/UVA-401 本题目比较水,主要考察常量数组的应用。 #include &amp;amp;amp;lt;ctype.h&amp;amp;amp;gt; #include &amp;amp;amp;lt;string.h&amp;amp;amp;gt; const char s[50] = &amp;amp;quot;A 3 HIL JM O 2TUVWXY51SE Z 8 &

qq_43185391的博客 124

UVA401

判断镜像串就逐个拿文本里的字符去查表,把对应的镜像字符拼起来,拼完再整体颠倒顺序和原文本对比,一致才算是镜像串。镜像字符串的定义:将字符串里每个字符替换为它对应的镜像字符(若该字符存在镜像),再把替换后的整个字符串反转,最终得到的字符串和原字符串完全相同。例如字符串 “3AIAE” 就是镜像字符串,A 和 I 的镜像就是自身,3 和 E 互为对方的镜像字符。输入由若干行字符串组成,每行一条字符串,字符串长度 1~20,且全部由合法字符构成,不存在非法字符,程序需要持续读取输入直到文件末尾。

2401_85048117的博客 153

UVA - 401 Palindromes

UVA - 401 Palindromes题目大意:给定一个字符串判断是否回文 是什么样打回文解题思路:。。强行扫#include <iostream> #include <cstdio> using namespace std; int main () { string a,c; bool f; int t = 1; while (cin>>a ) {

cwb15505905513的博客 288

Palindromes UVA - 401

Palindromes UVA - 401 题目传送门:https://vjudge.net/problem/UVA-401(平台VJ); 题目大意: 给你一个字符串,判断它是否是回文字符串,或者它是一个镜像字符串,或者它是什么都不是; 镜像字符串,比如J -> L , E -> 3, Z -> 5,等等,就是看起来和它相反的数字或字符 AC Code: #include #i

BackToMe的博客 402

UVA 401-Palindromes

UVA 401-Palindromes题目大意: 给个字符串,判断是否回文或者镜面回文解题思路: 先判断是否回文再判断是否镜面回文#include <stdio.h> #include <string.h> #include <iostream> using namespace std; void swap(char *a) { switch(*a) { case 'A':

ZeroLH00的博客 413

UVA-401(模拟题)

Palindromes UVA - 401 问题描述: 输入输出说明: 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 palindr

雪岩的博客 487

Palindromes--uva401

problem linkhttps://vjudge.net/problem/UVA-401analysis这道题的技巧很好,很喜欢,感觉能学到蛮多东西code#include<cstdio> #include<cstring> #include<cctype> const char* rev = "A 3 HIL JM O 2TUVWXY51SE Z 8 "; const char*

爱敲代码的小鼠的博客 418

UVA-401 Palindromes

2016-07-12 UVA - 401 Palindromes 题目大意:判断是否回文、镜面。回文即从左往右与从右往左相同。镜面根据所提供的表格,可能存在非法字符。一开始理解错题意,以为不存在非法字符就是镜面,实际上是从左往右根据表格将全部字符化为镜像后,要与从右往左相同。 解题思路:遍历每个元素,进行回文的判断,是回文的话tag[0] = 1 ,不是的话tag[0]

振丿Love 383

uva 401 Palindromes

uva 401 Palindromes 题目大意:判断一个字符串是不是回文、镜像字符串。 解题思路:逐一判断。 PS:注意!!格式!!少个空格害死人!!O和0是相等不是镜像!!! #include #include int main() { char ch[200], flag1 = 0, flag2 = 0,flag3 = 0; while (scanf("%s", ch)

总有那么一群人喜欢盯着我的博客看,估计这是他们见过最长的博客名,我必须得告诉他们博客名最长可以写多长 487

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

Palindromes  UVA - 401  题目传送门 题目大意:给你一个字符串,判断其是回文串还是镜像串。 AC代码: #include &lt;cstdio&gt; #include &lt;iostream&gt; #include &lt;algorithm&gt; #include &lt;cmath&gt; #include &lt;cstdlib&gt; #inclu...

C++的星空 386

UVA401 --- Palindromes

UVA401 --- Palindromes A regular palindrome is a string of numbers or letters that is the same forward as backward. For example, the string “ABCDEDCBA” is a palindrome because it is the same when t...

来日浅谈的博客 522

UVa 401 Palindromes

UVa 401 Palindromes 唔……这个题,抄的书,因为要是我写的话只能暴力了,反正暴力的量也不是很大嘛,但是总有暴力解决不了的时候,所以……我是不是之前就是这么一步步被拉下的? 今天学了个新函数 isalpha(); A regular palindrome is a string of numbers or letters that is the same forward ...

mandiheyanyu的博客 234

Uva 401 Palindromes

Uva 401 PalindromesA regular palindrome is a string of numbers or letters that is the same forward as backward. For example, the string “ABCDEDCBA” is a palindrome because it is the same when the str

long-long-ago 402
上一篇: c++ STL 生成排列
下一篇: uva 10361 Automatic Poetry
hao5743
博客等级 码龄15年 62粉丝 142原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值