problem link;
Discuss: this is simple problem to apply.just try it.
try yourself before see the code
#include<bits/stdc++.h>
using namespace std;
void rev(string &str)
{
int n,i,j;
n=str.length();
for(i=0;i<n/2;i++)
{
swap(str[i],str[n-i-1]);
}
}
int mirr(string &str)
{
int n,i,j,flag=0;
n=str.length();
for(i=0;i<=ceil(n/2);i++)
{
//cout <<'y';
if(str[i]=='A'&&(str[n-i-1]!='A'))
flag=1;
else if(str[i]=='E'&&(str[n-i-1]!='3'))
flag=1;
else if(str[i]=='H'&&(str[n-i-1]!='H'))
flag=1;
else if(str[i]=='I'&&(str[n-i-1]!='I'))
flag=1;
else if(str[i]=='J'&&(str[n-i-1]!='L'))
flag=1;
else if(str[i]=='O'&&(str[n-i-1]!='O'))
flag=1;
else if(str[i]=='M'&&(str[n-i-1]!='M'))
flag=1;
else if(str[i]=='L'&&(str[n-i-1]!='J'))
flag=1;
else if(str[i]=='S'&&(str[n-i-1]!='2'))
flag=1;
else if(str[i]=='T'&&(str[n-i-1]!='T'))
flag=1;
else if(str[i]=='U'&&(str[n-i-1]!='U'))
flag=1;
else if(str[i]=='V'&&(str[n-i-1]!='V'))
flag=1;
else if(str[i]=='W'&&(str[n-i-1]!='W'))
flag=1;
else if(str[i]=='X'&&(str[n-i-1]!='X'))
flag=1;
else if(str[i]=='Y'&&(str[n-i-1]!='Y'))
flag=1;
else if(str[i]=='Z'&&(str[n-i-1]!='5'))
flag=1;
else if(str[i]=='1'&&(str[n-i-1]!='1'))
flag=1;
else if(str[i]=='2'&&(str[n-i-1]!='S'))
flag=1;
else if(str[i]=='3'&&(str[n-i-1]!='E'))
flag=1;
else if(str[i]=='5'&&(str[n-i-1]!='Z'))
flag=1;
else if(str[i]=='8'&&(str[n-i-1]!='8'))
flag=1;
else if(str[i]!='A'&&str[i]!='E'&&str[i]!='H'&&str[i]!='I'&&str[i]!='J'&&str[i]!='O'&&str[i]!='M'&&str[i]!='L'&&str[i]!='S'&&str[i]!='T'&&str[i]!='U'&&str[i]!='V'&&str[i]!='W'&&str[i]!='X'&&str[i]!='Y'&&str[i]!='Z'&&str[i]!='1'&&str[i]!='2'&&str[i]!='3'&&str[i]!='5'&&str[i]!='8')
{
flag=1;
}
// cout <<str[i]<<' '<<flag;
if(flag)
break;
}
if(!flag)
return true;
return false;
}
int main()
{
//freopen("input.txt","r",stdin);
//freopen("out.txt","w",stdout);
string str;
while(cin >>str)
{
int n,i,j,cnt=0,flag=0,palin=0,mirror=0;
string rv,mir;
rv=str;
rev(rv);
if(rv==str)
palin=1;
if(mirr(str)==1)
mirror=1;
//out <<mirr(str);
if(palin==0&&mirror==0)
cout <<str<<" -- is not a palindrome.\n";
else if(palin==1&&mirror==0)
cout <<str<<" -- is a regular palindrome.\n";
else if(palin==0&&mirror==1)
cout <<str<<" -- is a mirrored string.\n";
else if(palin&&mirror)
cout <<str<<" -- is a mirrored palindrome.\n";
str.clear();
cout <<endl;
}
return 0;
}
Discuss: this is simple problem to apply.just try it.
try yourself before see the code
#include<bits/stdc++.h>
using namespace std;
void rev(string &str)
{
int n,i,j;
n=str.length();
for(i=0;i<n/2;i++)
{
swap(str[i],str[n-i-1]);
}
}
int mirr(string &str)
{
int n,i,j,flag=0;
n=str.length();
for(i=0;i<=ceil(n/2);i++)
{
//cout <<'y';
if(str[i]=='A'&&(str[n-i-1]!='A'))
flag=1;
else if(str[i]=='E'&&(str[n-i-1]!='3'))
flag=1;
else if(str[i]=='H'&&(str[n-i-1]!='H'))
flag=1;
else if(str[i]=='I'&&(str[n-i-1]!='I'))
flag=1;
else if(str[i]=='J'&&(str[n-i-1]!='L'))
flag=1;
else if(str[i]=='O'&&(str[n-i-1]!='O'))
flag=1;
else if(str[i]=='M'&&(str[n-i-1]!='M'))
flag=1;
else if(str[i]=='L'&&(str[n-i-1]!='J'))
flag=1;
else if(str[i]=='S'&&(str[n-i-1]!='2'))
flag=1;
else if(str[i]=='T'&&(str[n-i-1]!='T'))
flag=1;
else if(str[i]=='U'&&(str[n-i-1]!='U'))
flag=1;
else if(str[i]=='V'&&(str[n-i-1]!='V'))
flag=1;
else if(str[i]=='W'&&(str[n-i-1]!='W'))
flag=1;
else if(str[i]=='X'&&(str[n-i-1]!='X'))
flag=1;
else if(str[i]=='Y'&&(str[n-i-1]!='Y'))
flag=1;
else if(str[i]=='Z'&&(str[n-i-1]!='5'))
flag=1;
else if(str[i]=='1'&&(str[n-i-1]!='1'))
flag=1;
else if(str[i]=='2'&&(str[n-i-1]!='S'))
flag=1;
else if(str[i]=='3'&&(str[n-i-1]!='E'))
flag=1;
else if(str[i]=='5'&&(str[n-i-1]!='Z'))
flag=1;
else if(str[i]=='8'&&(str[n-i-1]!='8'))
flag=1;
else if(str[i]!='A'&&str[i]!='E'&&str[i]!='H'&&str[i]!='I'&&str[i]!='J'&&str[i]!='O'&&str[i]!='M'&&str[i]!='L'&&str[i]!='S'&&str[i]!='T'&&str[i]!='U'&&str[i]!='V'&&str[i]!='W'&&str[i]!='X'&&str[i]!='Y'&&str[i]!='Z'&&str[i]!='1'&&str[i]!='2'&&str[i]!='3'&&str[i]!='5'&&str[i]!='8')
{
flag=1;
}
// cout <<str[i]<<' '<<flag;
if(flag)
break;
}
if(!flag)
return true;
return false;
}
int main()
{
//freopen("input.txt","r",stdin);
//freopen("out.txt","w",stdout);
string str;
while(cin >>str)
{
int n,i,j,cnt=0,flag=0,palin=0,mirror=0;
string rv,mir;
rv=str;
rev(rv);
if(rv==str)
palin=1;
if(mirr(str)==1)
mirror=1;
//out <<mirr(str);
if(palin==0&&mirror==0)
cout <<str<<" -- is not a palindrome.\n";
else if(palin==1&&mirror==0)
cout <<str<<" -- is a regular palindrome.\n";
else if(palin==0&&mirror==1)
cout <<str<<" -- is a mirrored string.\n";
else if(palin&&mirror)
cout <<str<<" -- is a mirrored palindrome.\n";
str.clear();
cout <<endl;
}
return 0;
}
No comments:
Post a Comment