UIU: Competitive Programming: Palindrome


Palindrome Check


// @BEGIN_OF_SOURCE_CODE
 
#include <cstdio>
#include <cstring>
#import <algorithm>
 
using namespace std;
 
bool isPalindrome(char str [])
{
    int length = strlen (str);
 
    char copy [length];
 
    // making a copy of original string
    strcpy(copy, str);
 
    reverse(copy, copy + length);
 
    return strcmp(copy, str) == 0;
}
 
int main(int argc, const char * argv[])
{
    char input [100];
 
    scanf ("%s", input);
 
    if (isPalindrome(input)) {
        printf ("Palindrome\n");
 
    } else {
        printf ("Not Palindrome\n");
    }
 
    return 0;
}
 
// @END_OF_SOURCE_CODE

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