HD2029
4220 ワード
Palindromes _easy version
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 16932 Accepted Submission(s): 10643
Problem Description
「回文列」は正読みと反読みが同じ文字列で、例えば「level」や「noon」などが回文列です.読み込んだ文字列が「返信」であるかどうかを判断するプログラムを書いてください.
Input
入力には複数のテストインスタンスが含まれ、入力データの最初の行は正の整数nであり、テストインスタンスの個数を表し、後にn文字列が続く.
Output
文字列がエコー列である場合は「yes」を出力、そうでない場合は「no」を出力する.
Sample Input
4 level abcde noon haha
Sample Output
yes no yes no
これはとても水の問題で、前に『accelerated c++』で学んだ判断文の方法ですぐに秒殺しました.
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 16932 Accepted Submission(s): 10643
Problem Description
「回文列」は正読みと反読みが同じ文字列で、例えば「level」や「noon」などが回文列です.読み込んだ文字列が「返信」であるかどうかを判断するプログラムを書いてください.
Input
入力には複数のテストインスタンスが含まれ、入力データの最初の行は正の整数nであり、テストインスタンスの個数を表し、後にn文字列が続く.
Output
文字列がエコー列である場合は「yes」を出力、そうでない場合は「no」を出力する.
Sample Input
4 level abcde noon haha
Sample Output
yes no yes no
これはとても水の問題で、前に『accelerated c++』で学んだ判断文の方法ですぐに秒殺しました.
#include<iostream>
#include<string>
using namespace std;
bool is_palindrome(const string s){
return equal(s.begin(),s.end(),s.rbegin());
}
int main(){
int n;
cin>>n;
while(n--){
string s;
cin>>s;
if(is_palindrome(s))
cout<<"yes"<<endl;
else
cout<<"no"<<endl;
}
return 0;
}
, visual6.0 , dec c++ , :
#include<iostream>
#include<string>
using namespace std;
int main(){
int n;
cin>>n;
while(n--){
string s1;
cin>>s1;
string s2(s1.rbegin(),s1.rend());
if(s1==s2)
cout<<"yes"<<endl;
else
cout<<"no"<<endl;
}
return 0;
}