// Name : find.cpp
// Author : mtt
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
#include <string.h>
#include <string>
#include <fstream>
#include <vector>
using namespace std;
string s[3];
int main ()
{
ifstream in("33");
int i=0;
vector<string> s1,s2;
while(getline(in,s[i]))
{
cout<<s[i]<<endl;
i++;
}
string line= s[0]+s[1]+s[2];
cout<<line<<endl;
string separators(" \t:,\v\r\n\f"),word;
int start=0,end=0,pos=0,count=0,wordlen=0;
int max=0,min=0;
while ((start=line.find_first_not_of(separators,end))!=string::npos)
{
count++;
end =line .find_first_of(separators,start);
if (end==string::npos)//最后一个单词
{
wordlen=line.size()-start;
}
else {
wordlen=end-start;
}
word.assign(line.begin()+start,line.begin()+start+wordlen);
cout<<word<<endl;
cout<<wordlen<<endl;
if (count==1)
{
max=min=wordlen;
s1.push_back(word);
s2.push_back(word);
}
else
{
if(wordlen>max)
{
max=wordlen;
s1.clear();
s1.push_back(word);
}
if(wordlen==max)
{
s1.push_back(word);
}
if(wordlen<min)
{
min=wordlen;
s2.clear();
s2.push_back(word);
}
if(wordlen==min)
{
s2.push_back(word);
}
}
}
vector<string>::iterator it;
for(it=s1.begin();it!=s1.end();it++)
{
cout<<*it<<endl;
}
for(it=s2.begin();it!=s2.end();it++)
{
cout<<*it<<endl;
}
return 0;
}
原文链接: https://www.cnblogs.com/panlijiao/archive/2012/11/07/2773844.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/68523
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!