题目:A-1;
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it’s easy to make a mistake during the «translation». Vasya translated word s from Berlandish into Birlandish as t. Help him: find out if he translated the word correctly.
Input
The first line contains word s, the second line contains word t. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
Output
If the word t is a word s, written reversely, print YES, otherwise print NO.
Examples
Input
code
edoc
Output
YES
Input
abb
aba
Output
NO
Input
code
code
Output
NO
大意;输入两串字符串;长度要相等;如果两字符串互为逆序则输出YES;否则输出NO;
思路:先判断两字符串是否相等,并计算字符串长度。然后再判断两字符串是否互为逆序。
#include<iostream>
using namespace std;
bool A(char a[], char b[], int n)
{
for (int j = 0; j < n; j++)
{
if (a[j] != b[n - 1 - j])
return false;
}
return true;
}
int main()
{
char a[101], b[101];
cin >> a >> b;
int length = 0;
for (int i = 0; a[i] != '\0'; i++)
length++;
int m = 0;
for (int i = 0; b[i] != '\0'; i++)
m++;
if (length != m)
cout << "NO";
else if (A(a, b, length))
cout << "YES";
else
cout << "NO";
return 0;
}