Getting string translation problem solution exercises Planet 10 languages

Topic Description: http://codeforces.com/problemset/problem/41/A
here to do some changes on the basis of the original title.

Title Description

Lingling recently received a translation.
He needs to translate a text into Jupiter Saturn text.
Saturn and Jupiter are known Wen Wen is the 26 lowercase English letters.
The difference between Saturn and Jupiter Wen Wen Wen is the only that Jupiter Saturn paper read backwards. For example, Saturn text of the "code" has been translated into Jupiter text is "edoc".
Lingling now received a Saturn text, and he translated a good first draft text of Jupiter, would you please help confirm whether Lingling translation no problem.

Input Format

The first line of the input string has a non-null only lowercase letters to represent text Saturn.
The second line of the input string has a non-null only lowercase letters to represent Lingling Jupiter text translation.
Title ensure that the length of the two strings are not more than 100.

Output Format

If the translation results Lingling's no problem, output "YES"; otherwise, output "NO".

Sample input 1

code
edoc

Sample output 1

YES

Sample input 2

abb
aba

Sample output 2

NO

Sample input 3

code
code

Sample output 3

NO

Topic analysis

This is to open a for loop, then a start to finish, a head from tail, one by one comparison are the same on it.
But note here is that I buried a pit, that is, two strings of different lengths of time, is "NO".
Codes are as follows:

#include <bits/stdc++.h>
using namespace std;

string s, t;
int n, m;

bool check() {
    n = s.length();
    m = t.length();
    if (n != m) return false;
    for (int i = 0; i < n; i ++) if (s[i] != t[n-1-i]) return false;
    return true;
}

int main() {
    cin >> s >> t;
    puts( check() ? "YES" : "NO" );
    return 0;
}

Guess you like

Origin www.cnblogs.com/zifeiynoip/p/11450597.html