HDU-2029 Palindromes_easy version

See the article on https://dyingdown.github.io/2019/12/20/HDU-2029%20Palindromes-easy-version/

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

#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;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章