UVa-401-Palindromes

AOAPC I: Beginning Algorithm Contests (Rujia Liu) :: Volume 1. Elementary Problem Solving ::String


// 401 - Palindromes
#include <iostream>
#include <cstring>
using namespace std;

char Character[] = "AEHIJLMOSTUVWXYZ12358\0";
char Reverse[]   = "A3HILJMO2TUVWXY51SEZ8\0";

int main(void)
{
	bool regular, mirrored;
	char s[100];
	int i, len, pos;
	while(cin >> s)
	{
		regular = false;
		mirrored = false;
		len = strlen(s);

		for(i=0; i<=len/2; i++)
			if(s[i] != s[len-1-i])
				break;
		if(i == len/2+1)
			regular = true;

		for(i=0; i<=len/2; i++)
		{
			if(strchr(Character, s[i]) == NULL)
				break;
			pos = strchr(Character, s[i]) - Character;
			if(s[len-1-i] != Reverse[pos])
				break;
		}
		if(i == len/2+1)
			mirrored = true;

		if(regular && mirrored)
			cout << s << " -- is a mirrored palindrome." << endl << endl;
		else if(regular && !mirrored)
			cout << s << " -- is a regular palindrome." << endl << endl;
		else if(!regular && mirrored)
			cout << s << " -- is a mirrored string." << endl << endl;
		else
			cout << s << " -- is not a palindrome." << endl << endl;
	}
	return 0;
}



 

posted @ 2014-08-10 16:03  颜威  阅读(115)  评论(0编辑  收藏  举报