ORIGIN

HDU-2029 Palindromes_easy version

ACM 1 min147 words

Palindromes_easy version

A “palindrome string” is a string that is the same as both the forward and reverse reading. For example, “level” or “noon” is a palindrome string. Please write a program to determine whether the read string is “palindrome”.

Input

The input contains multiple test instances. The first line of input data is a positive integer n, which represents the number of test instances, followed by n strings.

Output

If a string is a palindrome, it outputs “yes”, otherwise it outputs “no”.

Analysis

Using C++ 11 features. reverse.

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include<bits/stdc++.h>

using namespace std;

int main() {
int t;
cin >> t;
while(t --) {
string a, b;
cin >> a;
b = a;
reverse(b.begin(), b.end());
if(a == b) cout << "yes" << endl;
else cout << "no" << endl;
}
return 0;
}
TOP
COMMENT
  • ABOUT
  • |
o_oyao
  The Jigsaw puzzle is incomplete with even one missing piece. And I want to be the last piece to make the puzzle complete.
Like my post?
Default QR Code
made with ❤️ by o_oyao
©o_oyao 2019-2024

|