C++ primer

/根据形参所指定的文件建立单词排除集

//被排除的单词放在vecter容器中

//并从标准输入设备读入文本,对不在排除集中的单词存在关联容器中

 

#include <iostream>

#include <map>

#include <string>

#include <fstream>

#include <vector>

#include <algorithm>

 

using namespace std;

 

void wc(ifstream&remove_file,map<string,int> &word_count)

{

    vector<string> excl;

    stringremove_word;

    while(remove_file >> remove_word)

    {

       excl.push_back(remove_word);

    }

   

    stringword;

    while(cin>>word)

      

    {

 

       /*vector<string>::iteratorit = excl.begin();

       for (;it !=excl.end();++it)

       {

            if ((*it)== word)

            {

              break;

            }

       }

       if (it ==excl.end())

       {

           ++word_count[word];

       } */

      

       if( find(excl.begin(),excl.end(),word) == excl.end() )

       {

                   ++word_count[word];

       }

    }

 

}

 

int main()

{

    map<string,int>word_C;

    stringfileName;

 

    cout<<"Enter fileName:"<<endl;

    cin>> fileName;

 

    ifstreamexfile(fileName.c_str());

    if(!exfile)

    {

       cout<<"error:没有找到该文件"<<endl;

       return-1;

    }

   

    wc(exfile,word_C);

 

    cout<< "输出结果如下:";

    map<string,int>::iterator iter=word_C.begin();

    while(iter != word_C.end())

    {

       cout<< iter->first<<" "<<iter->second<<endl;

       ++iter;

    }

    return0;

}

 

10.25

#include <iostream>

#include <vector>

#include <set>

#include <string>

#include <ctime>

#include <cstdlib>

using namespace std;

 

int main()

{

    vector<string>Wread;

    set<string>Hread;

    stringname;

 

    cout<<"建立未来个月要读的书的名字"<<endl;

    while(cin >> name)

    {

       Wread.push_back(name);

    }

 

    cin.clear();

 

    booltimeover = false;

    stringanswer;

    stringbookname;

    srand((unsigned)time(NULL));

 

 

    while(!Wread.empty()&& !timeover )

    {

       cout<<"would you like reading(Y/N)? "<<endl;

       cin>>answer;

       if(answer == "Y"||answer == "y")

       {

           //inti = (int)rand()% Wread.size();

           //bookname = Wread[i];

           cout<<"请输入你要读的书的名字"<<endl;

              cin>>bookname;

 

           //Wread.erase(Wread.begin()+i);

              for (vector<string>::iteratorit = Wread.begin();it != Wread.end();++it)

              {

                  if (*it == bookname)

                  {

                     Wread.erase(it);

                     break;

                  }

              }

           Hread.insert(bookname);

       }

 

       cout<< "did you read the book?"<<endl;

       cin>>answer;

       if(answer == "N"||answer == "n")

       {  

           Hread.erase(bookname);

            Wread.push_back(bookname);

       }

 

       cout<<"time if over?"<<endl;

       cin>>answer;

       if(answer == "Y"||answer  == "y")

       {

             timeover = true;

       }

      

    }

   

    if(timeover)

    {

       cout<< "没有读过的书:"<<endl;

       for(vector<string>::iterator it = Wread.begin();it!= Wread.end();++it)

       {

           cout<< (*it)<<endl;

       }

      

       cout<<"读过的书:"<<endl;

       for(set<string>::iterator it = Hread.begin();it != Hread.end();++it)

       {

           cout<<(*it);

       }

 

 

    }

 

return 0;

 

 

}

微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值