Code: Select all
Removed after AC
Thank you.
Moderator: Board moderators
Code: Select all
Removed after AC
Code: Select all
cout<<str<<" -- is a regular plaindrome.\n"<<endl;
Code: Select all
cout<<str<<" -- is a regular palindrome.\n"<<endl;
Code: Select all
the code is removed after ac.
Thanks to JAN bhia.
Code: Select all
H22H
EVE
MJJM
J
YJ33JY
Code: Select all
H22H -- is a regular palindrome.
EVE -- is a regular palindrome.
MJJM -- is a regular palindrome.
J -- is a regular palindrome.
YJ33JY -- is a regular palindrome.
Code: Select all
REMOVED AFTER AC.
Code: Select all
Code: Select all
ISSEJML11JML322I
SV2OSV2
8SZSJYYL2528
Code: Select all
ISSEJML11JML322I -- is a mirrored string.
SV2OSV2 -- is a mirrored string.
8SZSJYYL2528 -- is a mirrored string.
Code: Select all
#include<stdio.h>
#include<string.h>
int main (void)
{
int i,j,k,p,q;
char ch[21];
char ch1[21]={'A','E','H','I','J','L','M','O','S','T','U','V','W','X','Y','Z','1','2','3','5','8'};
char ch2[21]={'A','3','H','I','L','J','M','O','2','T','U','V','W','X','Y','5','1','S','E','Z','8'};
while(scanf("%s",ch)!=EOF)
{
p=0;
q=0;
for (i=0,j=strlen(ch)-1;i<=j/2;i++,j--)
{
if (ch[i]!=ch[j])
{
p=1;
break;
}
}
for (i=0,j=strlen(ch)-1;i<=j/2;i++,j--)
{
for(k=0;k<21;k++)
{
if (ch[i]==ch1[k])
{
break;
}
}
if(k==21||ch[j]!=ch2[k])
{
q=1;
break;
}
}
if (p&&q)
{
printf ("%s -- is not a palindrome\n\n",ch);
}
else if(p==0&&q)
{
printf ("%s -- is a regular palindrome\n\n",ch);
}
else if (p&&q==0)
{
printf ("%s -- is a mirrored string\n\n",ch);
}
else if(p==0&&q==0)
{
printf ("%s -- is a mirrored palindrome\n\n",ch);
}
}
return 0;
}
Code: Select all
#include <stdio.h>
#include <string.h>
/* check if a given string is palindrome */
int isPalindrome(char *s)
{
int i, j;
for (i = 0, j = strlen(s) - 1; i <= j; ++i, --j) {
if (s[i] != s[j])
return 0;
}
return 1;
}
/* check if a given string is mirrored */
int isMirror(char *s)
{
int i, j, c, k;
char *nonReversed = "BCDFGKNPQR04679"; /* not valid characters.(unreversable characters) */
/* reversed characters with their reverse */
char mirror[21][2] = {{'A', 'A'}, {'E', '3'}, {'H', 'H'}, {'I', 'I'}, {'J', 'L'}, {'L', 'J'},
{'M', 'M'}, {'O', 'O'}, {'S', '2'}, {'T', 'T'}, {'U', 'U'}, {'V', 'V'},
{'W', 'W'}, {'X', 'X'}, {'Y', 'Y'}, {'Z', '5'}, {'1', '1'},
{'2', 'S'}, {'3', 'E'}, {'5', 'Z'}, {'8', '8'}};
/* if given string has a character that cannot be reversed
* the string is sure not mirrored */
for (i = 0; s[i] != '\0'; ++i) {
c = s[i];
for (j = 0; nonReversed[j] != '\0'; ++j) {
if (c == nonReversed[j]) {
return 0;
}
}
}
for (i = 0, j = strlen(s) - 1; i <= j; ++i, --j) {
for (k = 0; k < 21; ++k) {
if (mirror[k][0] == s[i]) {
if (s[j] != mirror[k][1]) {
return 0;
}
break;
}
}
}
return 1;
}
int main()
{
char name[30];
while (scanf("%s", name) != EOF) {
if (isPalindrome(name)) {
if (isMirror(name)) {
printf("%s -- is mirrored palindrome.\n");
}
else {
printf("%s -- is regular palindrome.\n");
}
}
else {
if (isMirror(name)) {
printf("%s -- is a mirrored string.\n");
}
else {
printf("%s -- is not a palindrome.\n");
}
}
printf("\n");
}
return 0;
}