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;
}


UVa401_Palindromes(小白书字符串专题)

Description   Palindromes  A regular palindrome is a string of numbers or letters that ...

UVA 题目401 - Palindromes

A regular palindrome is a string of numbers or letters that is the same forward as backward. For exa...
  • SJF0115
  • SJF0115
  • 2013年04月22日 15:18
  • 3792

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 ...
  • kdwycz
  • kdwycz
  • 2014年02月24日 23:27
  • 564

UVa 401 Palindromes (字符串匹配)

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

uva401Palindromes

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

uva401 - Palindromes结题报告

题目地址 :  http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&cate...

UVA-401 Palindromes

2016-07-12 UVA - 401 Palindromes 题目大意:判断是否回文、镜面。回文即从左往右与从右往左相同。镜面根据所提供的表格,可能存在非法字符。一开始理解错题意,以为不存...

uva 401 Palindromes(字符串处理)

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

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

 题意  给一个字符串 判定其是否为回文串和镜像串  回文串很好判断  镜像串对于每一个字符用数组保存它的镜像字符就行了  没有的就是空格 注意若字符串长度为奇数  中间那个字母必须是对称的才...
  • acvay
  • acvay
  • 2014年08月30日 09:28
  • 1041
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:UVa 401 Palindromes
举报原因:
原因补充:

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