cpp primer 验证 p346页
2010-01-09 12:05
232 查看
#include <string> #include <vector> #include <iostream> #include <algorithm> using namespace std; string make_plural(size_t ctr,const string &word, const string &ending) { return (ctr<=1) ? word : word+ending; //make_plural(wc, "word ", "s ")当输入中文本中 //word数大于一是在word后加s,为words为word的复数! } //comparison function to be used to sort by word length bool is_shorter(const string &s1,const string &s2) { return s1.size()<s2.size(); } //determine whether a length of a given word is 6 or more bool GT6(const string &s) { return s.size()>=6; } //main int main() { vector<string> words; //copy contents of each book into a single vector string next_word; while (cin>>next_word) { //insert next book's content at end of words words.push_back(next_word); } //sort words alphabetically for finding the duplicates sort(words.begin(),words.end()); //eliminate duplicate words vector<string>::iterator end_unique=unique(words.begin(),words.end()); words.erase(end_unique,words.end()); stable_sort(words.begin(),words.end(),is_shorter); vector<string>::size_type wc=count_if(words.begin(),words.end(),GT6); cout<<wc<<" "<<make_plural(wc,"word","s") <<" 6 characters or longer"<<endl; }
相关文章推荐
- cpp primer 验证 p325页 文本查讯程序
- Cpp_Primer--Chapter8--IO库
- CppPrimer笔记 Chapter19 特殊工具与技术
- Cpp Primer<<学习函数-重载函数_2
- C primer plus 第八章 字符输入输出与输入验证 编程练习 个人答案
- CPP Primer 5th 笔记(一)
- 第十一周项目1 - 二叉树算法验证.cpp
- Cpp_Primer--异常检测入门
- Cpp_Primer--学习的相关资源
- 《C++ Primer Plus》第五版 程序清单4.22 delete.cpp
- CppPrimer--顶层const与底层const
- cppPrimer2
- cppPrimer5
- cpp Primer exexcise 09_26
- 再看cpp primer(1)
- Cpp Primer<<学习函数-局部对象、内联函数、类的成员函数_1
- CppPrimer--数组名与指针& 函数名与函数指针
- Cpp Primer<<学习IO标准库--面向对象的标准库_4
- Cpp Primer<<学习IO标准库--文件模式、字符串流_7
- Cpp_Primer--using注意事项 与 Range-Based for