find.cpp

来源:互联网 发布:数据质量问题 编辑:程序博客网 时间:2024/06/07 03:55
//============================================================================
// 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;
}


原创粉丝点击