Description The translation from the Berland language into the Birlandlanguage is not an easy task. Those languages are very similar: aberlandish word differs from a birlandish word with the samemeaning a little: it is spelled (and pronounced) reversely. Forexample, a Berlandish word Input The first line contains word Output If the word Sample Input
Input
code edoc
Output
YES
Input
abb aba
Output
NO
Input
code code
Output
NO |
解法一:普通匹配
#include<iostream> using namespace std; int main() { char a[101],b[101],c[101]; int k,count; while(scanf("%s %s",a,b)!=EOF) { count=0; k=strlen(a); strcpy(c,strrev(b)); for(int i=0;i<k;i++) { if(c[i]==a[i]) count++; } if(count==k) printf("YES\n"); else printf("NO\n"); } return 0;
}
解法二:利用STL中的倒置函数 strrev
#include<iostream>
using namespace std;
int main()
{
char str2[102],str1[102];
while(cin>>str1>>str2)
{
if(strcmp(str1,strrev(str2))==0)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;