Critical Input & Output
2BBS -- is not a palindrome. B2SB -- is not a palindrome. BBB -- is a regular palindrome.কোড
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Problem : 401 - Palindromes.cpp | |
* Author : ~menon | |
*/ | |
#include <iostream> | |
#include <string> | |
#include <cstring> | |
#include <cstdio> | |
#include <map> | |
int main() | |
{ | |
// freopen("input.txt", "r", stdin); | |
std::string s1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789"; | |
std::string s2 = "A 3 HIL JM O 2TUVWXY51SE Z 8 "; | |
std::map <char, char> myMap; | |
// put the value into the myMap; | |
for(int i = 0; i < s1.size(); i++) { | |
myMap[s1[i]] = s2[i]; | |
} | |
char s[22]; | |
while(scanf("%s", &s) != EOF) | |
{ | |
int palindorm, mirrored, len; | |
len = strlen(s); | |
palindorm = mirrored = 1; | |
for(int i = 0; i <= len/2; i++) | |
{ | |
// check is palindrom; | |
if(s[i] != s[len - 1 - i]) { | |
palindorm = 0; | |
} | |
// check is morrored; | |
if(s[len - 1 - i] != myMap[s[i]]) { | |
mirrored = 0; | |
} | |
} | |
if(!palindorm && !mirrored) { | |
printf("%s -- is not a palindrome.\n\n",s); | |
} | |
else if(palindorm && !mirrored) { | |
printf("%s -- is a regular palindrome.\n\n", s); | |
} | |
else if(!palindorm && mirrored) { | |
printf("%s -- is a mirrored string.\n\n", s); | |
} | |
else if(palindorm && mirrored) { | |
printf("%s -- is a mirrored palindrome.\n\n", s); | |
} | |
} | |
return 0; | |
} |
Comments
Post a Comment