习题10.25的详细解答
#include"stdafx.h"
#include<iostream>
#include<set>
#include<vector>
#include<utility>
#include<string>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
vector<string> strVecBook;
string bName;
string strChoice;
cout<<"input the book you want to read:\n";
while(cin>>bName)
strVecBook.push_back(bName);
size_t NumOfBook=strVecBook.size();
set<string>strReadBook;
string bookName;
srand((unsigned)time(NULL));
bool _6MounthLater=false;
while(!_6MounthLater&&!strVecBook.empty()) //边界条件
{
cin.clear();
cout<<"Do you want to read the book? (Yes/No)\n"<<endl;
cin>>strChoice;
if(strChoice[0]=='Y'||strChoice[0]=='y')
{
int i=rand()%strVecBook.size();
bookName=strVecBook[i];
cout<<"we choose this book\t"<<bookName<<endl;
strReadBook.insert(bookName);
strVecBook.erase(strVecBook.begin()+i);
cout<<"after some time,do you really read it?(Yes/No)\n"<<endl;
cin>>strChoice;
if(strChoice[0]=='N'||strChoice[0]=='n')
{
strVecBook.push_back(bookName);
strReadBook.erase(bookName);
}
cout<<"6 mouth later?"<<endl;
cin>>strChoice;
if(strChoice[0]=='Y'||strChoice[0]=='y')
_6MounthLater=true;
}
cout<<"6 mouth later"<<endl;
if(_6MounthLater)
{
cout<<"the book you have read :\n";
for(set<string>::iterator it=strReadBook.begin();it!=strReadBook.end();++it)
cout<<*it<<" ";
cout<<endl;
cout<<"the book you have not read:\n";
for(vector<string>::iterator iter=strVecBook.begin();iter!=strVecBook.end();++iter)
cout<<*iter<<" ";
}
}
system("pause");
return 0;
}