UVa 401 - Palindromes
/*
Accepted
*/
#include<bits/stdc++.h>
using namespace std;
#define sf scanf
#define pf printf
#define psb push_back
#define fast ios_base::sync_with_stdio(false)
typedef map<string, int>mpsi;
typedef map<int, string>mpis;
typedef long long LL;
const int high = 2e5+10;
char checkReverse(char ch)
{
if(ch == 'A') return 'A';
else if(ch == 'A') return 'A';
else if(ch == 'E') return '3';
else if(ch == '3') return 'E';
else if(ch == 'H') return 'H';
else if(ch == 'I') return 'I';
else if(ch == 'J') return 'L';
else if(ch == 'L') return 'J';
else if(ch == 'M') return 'M';
else if(ch == 'O') return 'O';
else if(ch == 'S') return '2';
else if(ch == '2') return 'S';
else if(ch == 'T') return 'T';
else if(ch == 'U') return 'U';
else if(ch == 'V') return 'V';
else if(ch == 'W') return 'W';
else if(ch == 'X') return 'X';
else if(ch == 'Y') return 'Y';
else if(ch == 'Z') return '5';
else if(ch == '5') return 'Z';
else if(ch == '1') return '1';
else if(ch == '8') return '8';
else return '*';
}
bool checkPallindrome(string mainS)
{
string secondS = mainS;
reverse(secondS.begin(), secondS.end());
if(mainS == secondS) return true;
return false;
}
bool checkMirror(string mainS)
{
int len = 0, i;
len = mainS.length();
string tmpmainS = mainS , secondS = "";
len = tmpmainS.length();
for(i=0; i<len; i++)
{
char ch = checkReverse(tmpmainS[i]);
if(ch == '*') return false;
secondS += ch;
}
reverse(secondS.begin(), secondS.end());
//cout << secondS << "\n";
if(secondS == mainS) return true;
return false;
}
void Show(string thestr, string showstr)
{
cout << thestr << showstr << "\n\n";
}
int main()
{
fast;
string mainString;
bool isPallindrome = false, isMirror = false;
while(cin >> mainString)
{
int i , len = mainString.length();
isPallindrome = false;
isMirror = false;
isPallindrome = checkPallindrome(mainString);
isMirror = checkMirror(mainString);
if(!isPallindrome && !isMirror)
{
Show(mainString, " -- is not a palindrome.");
continue;
}
if(isPallindrome && !isMirror)
{
Show(mainString, " -- is a regular palindrome.");
continue;
}
if(!isPallindrome && isMirror)
{
Show(mainString, " -- is a mirrored string.");
continue;
}
if(isPallindrome && isMirror)
{
Show(mainString, " -- is a mirrored palindrome.");
continue;
}
}
return 0;
}
Accepted
*/
#include<bits/stdc++.h>
using namespace std;
#define sf scanf
#define pf printf
#define psb push_back
#define fast ios_base::sync_with_stdio(false)
typedef map<string, int>mpsi;
typedef map<int, string>mpis;
typedef long long LL;
const int high = 2e5+10;
char checkReverse(char ch)
{
if(ch == 'A') return 'A';
else if(ch == 'A') return 'A';
else if(ch == 'E') return '3';
else if(ch == '3') return 'E';
else if(ch == 'H') return 'H';
else if(ch == 'I') return 'I';
else if(ch == 'J') return 'L';
else if(ch == 'L') return 'J';
else if(ch == 'M') return 'M';
else if(ch == 'O') return 'O';
else if(ch == 'S') return '2';
else if(ch == '2') return 'S';
else if(ch == 'T') return 'T';
else if(ch == 'U') return 'U';
else if(ch == 'V') return 'V';
else if(ch == 'W') return 'W';
else if(ch == 'X') return 'X';
else if(ch == 'Y') return 'Y';
else if(ch == 'Z') return '5';
else if(ch == '5') return 'Z';
else if(ch == '1') return '1';
else if(ch == '8') return '8';
else return '*';
}
bool checkPallindrome(string mainS)
{
string secondS = mainS;
reverse(secondS.begin(), secondS.end());
if(mainS == secondS) return true;
return false;
}
bool checkMirror(string mainS)
{
int len = 0, i;
len = mainS.length();
string tmpmainS = mainS , secondS = "";
len = tmpmainS.length();
for(i=0; i<len; i++)
{
char ch = checkReverse(tmpmainS[i]);
if(ch == '*') return false;
secondS += ch;
}
reverse(secondS.begin(), secondS.end());
//cout << secondS << "\n";
if(secondS == mainS) return true;
return false;
}
void Show(string thestr, string showstr)
{
cout << thestr << showstr << "\n\n";
}
int main()
{
fast;
string mainString;
bool isPallindrome = false, isMirror = false;
while(cin >> mainString)
{
int i , len = mainString.length();
isPallindrome = false;
isMirror = false;
isPallindrome = checkPallindrome(mainString);
isMirror = checkMirror(mainString);
if(!isPallindrome && !isMirror)
{
Show(mainString, " -- is not a palindrome.");
continue;
}
if(isPallindrome && !isMirror)
{
Show(mainString, " -- is a regular palindrome.");
continue;
}
if(!isPallindrome && isMirror)
{
Show(mainString, " -- is a mirrored string.");
continue;
}
if(isPallindrome && isMirror)
{
Show(mainString, " -- is a mirrored palindrome.");
continue;
}
}
return 0;
}
Comments
Post a Comment