UVa 401 Palindromes

原创 2013年12月02日 00:17:32

UVa 401 

每例输出之间有一行空行。。


#include<cstring>
#include<cstdio>
#include<iostream>
using namespace std;

int cmirpal(char c){
	if(c=='A'||c=='H'||c=='I'||c=='M'||c=='O'||c=='T'||
			c=='U'||c=='V'||c=='W'||c=='X'||c=='Y'||c=='1'||c=='8')
		return 1;
	return 0;
}

int mir(char c1, char c2){
	if(c1=='E'&&c2=='3')
		return 1;
	if(c1=='3'&&c2=='E')
			return 1;
	if(c1=='L'&&c2=='J')
			return 1;
	if(c1=='J'&&c2=='L')
			return 1;
	if(c1=='S'&&c2=='2')
			return 1;
	if(c1=='2'&&c2=='S')
				return 1;
	if(c1=='Z'&&c2=='5')
			return 1;
	if(c1=='5'&&c2=='Z')
			return 1;
	return 0;
}

int main(){
	char str[25];
	char stack[12];
	int mirror = 1, palin = 1;
	while(scanf("%s",str)!=EOF){
		mirror = 1, palin = 1;
		int s = strlen(str);
		int idx = 0, i;
		memset(stack,0,sizeof(stack));
		for(i = 0;i<s/2;i++){
			stack[idx++] = str[i];
		}
		if(s%2){
			if(!cmirpal(str[i++])){
				mirror = 0;
				//printf("m%d ",i-1);//
			}
		}
		for(;i<s;i++){
			idx--;
			if(stack[idx]==str[i]){
				if(!cmirpal(str[i])){
					mirror = 0;
					//printf("m%d ",i);//
				}
			}
			else{
				palin = 0;
				//printf("p%d ",i);//
				if(!mir(stack[idx],str[i])){
					mirror = 0;
					//printf("m%d ",i);//
				}
			}
			if(!palin&&!mirror)
				break;
		}
		if(palin&&mirror)
			printf("%s -- is a mirrored palindrome.\n",str);
		else if(palin&&!mirror)
			printf("%s -- is a regular palindrome.\n",str);
		else if(!palin&&mirror)
			printf("%s -- is a mirrored string.\n",str);
		else
			printf("%s -- is not a palindrome.\n",str);
		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
  • 957

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个字)