Problem Type : String
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int mirror(char ch[],int len)
{
int i,j,p,cou;
p= len/2;
j=1;
cou=0;
for(i=0; i<len; i++)
{
if(ch[i]=='E' && ch[len-j]=='3')
{
cou++;
}
else if(ch[i]=='A' && ch[len-j]=='A')
{
cou++;
}
else if(ch[i]=='H' && ch[len-j]=='H')
{
cou++;
}
else if(ch[i]=='I' && ch[len-j]=='I')
{
cou++;
}
else if(ch[i]=='J' && ch[len-j]=='L')
{
cou++;
}
else if(ch[i]=='L' && ch[len-j]=='J')
{
cou++;
}
else if(ch[i]=='M' && ch[len-j]=='M')
{
cou++;
}
else if(ch[i]=='O' && ch[len-j]=='O')
{
cou++;
}
else if(ch[i]=='S' && ch[len-j]=='2')
{
cou++;
}
else if(ch[i]=='T' && ch[len-j]=='T')
{
cou++;
}
else if(ch[i]=='U' && ch[len-j]=='U')
{
cou++;
}
else if(ch[i]=='V' && ch[len-j]=='V')
{
cou++;
}
else if(ch[i]=='W' && ch[len-j]=='W')
{
cou++;
}
else if(ch[i]=='Y' && ch[len-j]=='Y')
{
cou++;
}
else if(ch[i]=='Z' && ch[len-j]=='5')
{
cou++;
}
else if(ch[i]=='1' && ch[len-j]=='1')
{
cou++;
}
else if(ch[i]=='2' && ch[len-j]=='S')
{
cou++;
}
else if(ch[i]=='3' && ch[len-j]=='E')
{
cou++;
}
else if(ch[i]=='5' && ch[len-j]=='Z')
{
cou++;
}
else if(ch[i]=='8' && ch[len-j]=='8')
{
cou++;
}
else
break;
// printf("%d",cou);
j++;
}
if(len==cou)
return 1;
else
return 0;
}
int main()
{
int i ,j,k,len;
char ch[1000],des[1000];
while(scanf("%s",ch)==1)
{
len = strlen(ch);
strcpy(des,ch);
reverse(des,des+len);
if(strcmp(ch,des)==0)
{
k=1;
}
else
{
k=0;
}
// printf("%d\n",len);
j=mirror(ch,len);
if(k==1 && j==1)
{
printf("%s -- is a mirrored palindrome.\n\n",ch);
}
else if(k==1 && j==0)
{
printf("%s -- is a regular palindrome.\n\n",ch);
}
else if(k==0 && j==1)
{
printf("%s -- is a mirrored string.\n\n",ch);
}
else if(k==0 && j==0)
{
printf("%s -- is not a palindrome.\n\n",ch);
}
memset(ch,'\0',sizeof(ch));
memset(des,'\0',sizeof(des));
}
}
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int mirror(char ch[],int len)
{
int i,j,p,cou;
p= len/2;
j=1;
cou=0;
for(i=0; i<len; i++)
{
if(ch[i]=='E' && ch[len-j]=='3')
{
cou++;
}
else if(ch[i]=='A' && ch[len-j]=='A')
{
cou++;
}
else if(ch[i]=='H' && ch[len-j]=='H')
{
cou++;
}
else if(ch[i]=='I' && ch[len-j]=='I')
{
cou++;
}
else if(ch[i]=='J' && ch[len-j]=='L')
{
cou++;
}
else if(ch[i]=='L' && ch[len-j]=='J')
{
cou++;
}
else if(ch[i]=='M' && ch[len-j]=='M')
{
cou++;
}
else if(ch[i]=='O' && ch[len-j]=='O')
{
cou++;
}
else if(ch[i]=='S' && ch[len-j]=='2')
{
cou++;
}
else if(ch[i]=='T' && ch[len-j]=='T')
{
cou++;
}
else if(ch[i]=='U' && ch[len-j]=='U')
{
cou++;
}
else if(ch[i]=='V' && ch[len-j]=='V')
{
cou++;
}
else if(ch[i]=='W' && ch[len-j]=='W')
{
cou++;
}
else if(ch[i]=='Y' && ch[len-j]=='Y')
{
cou++;
}
else if(ch[i]=='Z' && ch[len-j]=='5')
{
cou++;
}
else if(ch[i]=='1' && ch[len-j]=='1')
{
cou++;
}
else if(ch[i]=='2' && ch[len-j]=='S')
{
cou++;
}
else if(ch[i]=='3' && ch[len-j]=='E')
{
cou++;
}
else if(ch[i]=='5' && ch[len-j]=='Z')
{
cou++;
}
else if(ch[i]=='8' && ch[len-j]=='8')
{
cou++;
}
else
break;
// printf("%d",cou);
j++;
}
if(len==cou)
return 1;
else
return 0;
}
int main()
{
int i ,j,k,len;
char ch[1000],des[1000];
while(scanf("%s",ch)==1)
{
len = strlen(ch);
strcpy(des,ch);
reverse(des,des+len);
if(strcmp(ch,des)==0)
{
k=1;
}
else
{
k=0;
}
// printf("%d\n",len);
j=mirror(ch,len);
if(k==1 && j==1)
{
printf("%s -- is a mirrored palindrome.\n\n",ch);
}
else if(k==1 && j==0)
{
printf("%s -- is a regular palindrome.\n\n",ch);
}
else if(k==0 && j==1)
{
printf("%s -- is a mirrored string.\n\n",ch);
}
else if(k==0 && j==0)
{
printf("%s -- is not a palindrome.\n\n",ch);
}
memset(ch,'\0',sizeof(ch));
memset(des,'\0',sizeof(des));
}
}
No comments:
Post a Comment