//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; }
转载于:https://www.cnblogs.com/springside5/archive/2012/02/25/2486295.html