习题10.25

#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

转载于:https://my.oschina.net/ppppower/blog/36909

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值