c++编程回文
来源:百度知道 编辑:UC知道 时间:2024/06/30 17:00:57
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int isHuiwen(const string& str){
for(int i=0;i<str.length()/2;i++)
if(str[i]!=str[str.length()-i-1]) return 0;
return str.length();
}
int main(){
int n,max=0;
string word,maxWord;
vector<string> hwWords;
cout<<"input the number of words : ";
cin>>n;
for(int i=0;i<n;i++){
cin>>word;
if(isHuiwen(word)){
hwWords.push_back(word);
if(word.length()>max){
maxWord=word;
max=word.length();
}
}
}
cout<<"hui wen word list is:"<<endl;
for(int j=0;j<hwWords.size();j++)
cout<<hwWords[j]<