利用vector求最长最短单词
#include<iostream>#include<string>
#include<vector>
#include<algorithm>
using namespace std;
typedef vector<double>::size_type vec_sz;
int main(){
vector<string> passage;
vector<double> numble;
string x;
cout<<"Please input one passage:"<<endl;
while(cin>>x&&x!="0"){
passage.push_back(x);
}
vec_sz count,size=passage.size();
cout<<"The original passage is:"<<endl;
for(count=0;count!=size;count++)
cout<<passage[count]<<" ";
cout<<endl;
for(count=0;count!=size;count++)
numble.push_back(passage[count].size());
for(count=0;count!=size;count++)
cout<<numble[count]<<endl;
cout<<flush;
sort(numble.begin(),numble.end());
for(count=0;count!=size;count++)
cout<<numble[count]<<endl;
cout<<"The shortest words are:"<<endl;
for(count=0;count!=size;++count){
if(passage[count].size()==numble[0])
cout<<passage[count]<<endl;
}
cout<<"The longest words are:"<<endl;
for(count=0;count!=size;++count){
if(passage[count].size()==numble[size-1])
cout<<passage[count]<<endl;
}
return 0;
}
这个程序只能是想对没有标点的文章求最大最小单词,想问一下如何用vector实现对带标点的一段话求最长最短单词