uva--401 Palindromes

原创 2013年12月03日 20:58:32

题目:Palindromes

解题思路:判断是否为回文:判断字符串前n/2的第i个字符与第n-1-i个字符是否相同,都相同就是回文;判断是否为mirrored,判断字符串前n/2字符的第n-1-i个字符是否与第i个的镜像字符相同,都相同则是mirrored;要注意每个输出后面都要再打印一行空白行;

#include<stdio.h>
#include<string.h>

const int N = 50;
char *s1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789";
char *s2 = "A000300HIL0JM0O0002TUVWXY51SE0Z0080";

bool ispalindrome(char * s) {

	int i, n = strlen(s);
	for (i = 0;i <= n/2; i++)
		if (s[i] != s[n-1-i])
			return false;
		return true;
}
bool ismirrored (char * s) {

	int i,j,n = strlen(s);
	for (i = 0; i <= n/2; i++) {
		
		for (j = 0;s1[j] && s[i] != s1[j]; j++);
		if (s1[j])
			if (s[n-1-i] != s2[j])
				return false;
	}
	return true;
}
int main() {

	
	char s[N];
	bool m, p;
	int i,j;
	while (scanf("%s", &s) == 1) {

		p=ispalindrome(s);
		m=ismirrored(s);
		if(m && p )
			printf("%s -- is a mirrored palindrome.\n",s);
		else if (p)
			printf("%s -- is a regular palindrome.\n",s);
		else if (m)
			printf("%s -- is a mirrored string.\n",s);
		else 
			printf("%s -- is not a palindrome.\n",s);
		printf("\n");
	}
	return 0;
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

UVA 题目401 - Palindromes

A regular palindrome is a string of numbers or letters that is the same forward as backward. For exa...

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

 题意  给一个字符串 判定其是否为回文串和镜像串  回文串很好判断  镜像串对于每一个字符用数组保存它的镜像字符就行了  没有的就是空格 注意若字符串长度为奇数  中间那个字母必须是对称的才...
  • acvay
  • acvay
  • 2014-08-30 09:28
  • 968

UVa 401 Palindromes(简单字符串)

简单的判断是否是回文串、镜像串,然后自己写的真费劲,没逃掉刘汝佳的书,这里的代码很有技巧性,特别值得学习,额,其实他书上的代码都很精简 Character Reverse ...

UVA 题目401 - Palindromes(回文词)

A regular palindrome is a string of numbers or letters that is the same forward as backward. For exa...

UVA 401 Palindromes 字符串

Palindromes A regular palindrome is a string of numbers or letters that is the same forward as ...

UVa 401 Palindromes (字符串匹配)

401 - Palindromes Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlineju...

uva 401 Palindromes

简单字符串题目 #include #include #include #include using namespace std; map pal_map; char buffer[30];...

字符串与数组03-例题3 Palindromes,UVa401

A regular palindrome is a string of numbers or letters that is the same forward as backward. For exa...

uva401Palindromes

这个题的核心就是判断镜像字符串,镜像字符串是不能包含 没有reverse的字符的,例如B C 代码: #include #include char s[100]; bool is_...

UVa401_Palindromes(小白书字符串专题)

Description   Palindromes  A regular palindrome is a string of numbers or letters that ...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)