您的位置:首页 > 编程语言 > C语言/C++

C++ Primer 第10章 习题10.24

2012-02-25 14:20 375 查看
//10.24.cpp
//建立一个单词排除集
//用于识别以's'借位、但这个结尾的's',又不能删除的单词
//使用这个排除集删除输入单词尾部的's',生成该单词的非复数版本
//如果输入的是排除集中的单词,则保持该单词不变
#include<iostream>
#include<set>
#include<string>
using namespace std;

int main()
{
	set<string> excluded;

	//建立单词排除集
	excluded.insert("success");
	excluded.insert("class");
	//....//

	string word;
	cout<<"Enter a word(ctrl-z to end)"<<endl;
	//读入单词并根据排除集生成该单词的非复数版本
	while(cin>>word)
	{
		if(!excluded.count(word))	//该单词未在排除集合中出现
			word.resize(word.size()-1);	//去掉单词末尾的's'
		cout<<"non-plural version:"<<word<<endl;
		cout<<"Enter a word(Ctrl-z to end)"<<endl;
	}

	return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: