Translation
一、Translation
本题链接:
题目:
A. Translation
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
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
本博客给出本题截图:
题意:输入两个字符串,如果一个字符串reverse
一遍正好和另一个字符串一样的话,就输出YES
,否则输出NO
AC代码1
#include <iostream>
#include <string>
using namespace std;
int main()
{
string a, b;
cin >> a >> b;
bool flag = false;
for (int i = 0, j = b.size() - 1; i < a.size(); i ++, j -- )
if (a[i] != b[j])
{
flag = true;
break;
}
if (flag) puts("NO");
else puts("YES");
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
AC代码2
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
string a, b;
cin >> a >> b;
reverse(a.begin(), a.end());
if (a == b) puts("YES");
else puts("NO");
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
总结
水题,不解释
文章来源: chen-ac.blog.csdn.net,作者:辰chen,版权归原作者所有,如需转载,请联系作者。
原文链接:chen-ac.blog.csdn.net/article/details/117440563
- 点赞
- 收藏
- 关注作者
评论(0)