#include<iostream>
#include<map>
#include<set>
#include<string>
#include<vector>
#include<ctime>
using namespace std;
int main()
{
vector<string> svec;
set<string> sset;
cout<<"要读的书:"<<endl;
string booka;
while(cin>>booka)
svec.push_back(booka);
cin.clear();
srand((unsigned)time(NULL));
string str,book;
bool time_over=false;
while(!time_over&&!svec.empty()){
cout<<"Would you like to read a book>(YES/NO)\n";
cin>>str;
if(str[0]=='Y'||str[0]=='y'){
vector<string>::size_type i=rand()%svec.size();
book=svec[i];
cout<<"read book"<<book<<endl;
sset.insert(book);
svec.erase(svec.begin()+i);
cout<<"Did you read it?(y/n)\n";
cin>>str;
if(str[0]=='N'||str[0]=='n'){
sset.erase(book);
svec.push_back(book);
}
}
cout<<"Time over?(yes/no)\n";
cin>>str;
if(str[0]=='Y'||str[0]=='y')
time_over=true;
}
if(time_over){
cout<<"books read:"<<endl;
for(set<string>::iterator it=sset.begin();it!=sset.end();++it)
cout<<*it<<endl;
cout<<"books not read:"<<endl;
for(vector<string>::iterator ite=svec.begin();ite!=svec.end();++ite)
cout<<*ite<<endl;
}else
cout<<"Congratulations,you have read all these books!\n";
return 0;
}
c++ primer 习题10.25
最新推荐文章于 2024-05-22 19:56:55 发布