UVa : 11888 (Abnormal 89’s)



// http://uva.onlinejudge.org/external/118/11888.html
// Runtime : 0.072s
// Tag : Palindrome

// @BEGIN_OF_SOURCE_CODE

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <sstream>
#include <cmath>
#include <bitset>
#include <utility>
#include <set>
#include <numeric>
#define INT_MAX 2147483647
#define INT_MIN -2147483647
#define pi acos(-1.0)
#define N 1000000
#define LL unsigned long long
using namespace std;

char original [200000 + 5];

bool is_palin (int a, int b)
{
	while ( a < b ) {
		if ( original [a] != original [b - 1] ) return false;
		a++, b--;
	}

	return true;
}

int main ()
{
	int testCase;
	scanf ("%d", &testCase);

	while ( testCase-- ) {
		scanf ("%s", original);
		int len = strlen (original);
		bool found = false;

		for ( int i = 0; i < len - 1; i++ ) {
			if ( original [0] == original [i] && original [i + 1] == original [len - 1] ) {
				if ( is_palin (0, i + 1) && is_palin (i + 1, len) ) {
					found = true;
					printf ("alindrome\n");
					break;
				}
			}
		}

		if ( !found ) {
			if ( is_palin (0, len) ) printf ("palindrome\n");
			else printf ("simple\n");
		}
	}

	return 0;
}

// @END_OF_SOURCE_CODE
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s