//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;
}
C++ Primer 第10章 习题10.24
最新推荐文章于 2025-12-01 16:00:40 发布
本文介绍了一个简单的C++程序,该程序通过建立一个特定的单词排除集来处理英语单词复数形式。当遇到以's'结尾但不应被简化的单词时,程序会保留其原有形式;对于其他以's'结尾的单词,则去除这个's'以生成非复数形式。
345

被折叠的 条评论
为什么被折叠?



