#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
using namespace std;
int main()
{
vector<string> bookVec;
cout<<"***Enter some books you will read in next six month:"<<endl;
string book;
while(cin>>book)
bookVec.push_back(book);
cin.clear();
set<string> readbook; //the book in "readbook" has already read
cout<<"***Enter one book you want to read now(Ctrl+d to end):"<<endl;
string bookName;
while(cin>>bookName)
{
if(find(bookVec.begin(),bookVec.end(),bookName)==bookVec.end())
{
cout<<"***the book "<<bookName<<" is not in your read list,enter again(Ctrl+d to end)!"<<endl;
continue;
}
cout<<"***OK, now you want to read :"<<bookName<<endl;
//在set中标记一下准备读的书
readbook.insert(bookName);
cout<<"***Enter one book to read again(Ctrl+d to end):"<<endl;
}
cin.clear();
//some book are not read
cout<<"***Enter the book you select but not read(Ctrl+d):"<<endl;
while(cin>>bookName)
if(readbook.count(bookName))
readbook.erase(bookName);
else
{
cout<<"***The book you never select and enter again(Ctrl+d to end):"<<endl;
continue;
}
cin.clear();
//output
cout<<endl<<"***the book you have read are:"<<endl;
for(set<string>::iterator it=readbook.begin();it!=readbook.end();++it)
cout<<*it<<' ';
cout<<endl<<"***the book you have not read are:"<<endl;
for(vector<string>::iterator it=bookVec.begin();it!=bookVec.end();++it)
if(!readbook.count(*it))
cout<<*it<<' ';
cout<<endl;
return 0;
}
***Enter some books you will read in next six month:
c++compier linuxprogramming datastructure
***Enter one book you want to read now(Ctrl+d to end):
c++compier
***OK, now you want to read :c++compier
***Enter one book to read again(Ctrl+d to end):
linuxprogramming
***OK, now you want to read :linuxprogramming
***Enter one book to read again(Ctrl+d to end):
***Enter the book you select but not read(Ctrl+d):
linuxprogramming
***the book you have read are:
c++compier
***the book you have not read are:
linuxprogramming datastructure