C++ Primer 第10章 习题10.24
生活随笔
收集整理的這篇文章主要介紹了
C++ Primer 第10章 习题10.24
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
//10.24.cpp //建立一個單詞排除集 //用于識別以's'借位、但這個結(jié)尾的's',又不能刪除的單詞 //使用這個排除集刪除輸入單詞尾部的's',生成該單詞的非復數(shù)版本 //如果輸入的是排除集中的單詞,則保持該單詞不變 #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; //讀入單詞并根據(jù)排除集生成該單詞的非復數(shù)版本 while(cin>>word) { if(!excluded.count(word)) //該單詞未在排除集合中出現(xiàn) word.resize(word.size()-1); //去掉單詞末尾的's' cout<<"non-plural version:"<<word<<endl; cout<<"Enter a word(Ctrl-z to end)"<<endl; } return 0; }
轉(zhuǎn)載于:https://www.cnblogs.com/springside5/archive/2012/02/25/2486295.html
總結(jié)
以上是生活随笔為你收集整理的C++ Primer 第10章 习题10.24的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C#中ListT用法
- 下一篇: C++读取INI文件