UVa 401 Palindromes

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
上一篇UVa 102 Ecological Bin Packing
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭