#ifndef COUNT_WORD_H
#define COUNT_WORD_H #include <string.h>
#include <iostream>
#include <iterator>
#include <vector>
#include <algorithm> class GT_cls{
public:
GT_cls(size_t val = 0)
:bound_(val){}
bool operator()(const std::string &s){
return s.size() >= bound_;
}
private:
std::string::size_type bound_;
}; class Word_count{
public:
Word_count(size_t val)
:GT_(val), wc_(0){}
void readWord();
void process();
void display();
private:
static bool isShorter(const std::string &s1, const std::string &s2);
std::vector<std::string> words_;
GT_cls GT_;
size_t wc_;
}; inline void Word_count::readWord(){
std::istream_iterator<std::string> cin_it(std::cin);
std::istream_iterator<std::string> end_of_stream;
while(cin_it != end_of_stream){
words_.push_back(*cin_it++);
}
} inline void Word_count::process(){
sort(words_.begin(), words_.end());
std::vector<std::string>::iterator end_unique = \
unique(words_.begin(), words_.end());
words_.erase(end_unique, words_.end());
stable_sort(words_.begin(), words_.end(), isShorter);
wc_ = count_if(words_.begin(), words_.end(), GT_);
} inline void Word_count::display(){
std::cout << "There are " << wc_ << " words." << std::endl;
for(std::vector<std::string>::iterator it = words_.begin(); it != words_.end(); ++it){
std::cout << *it << " ";
}
std::cout << std::endl;
} inline bool Word_count::isShorter(const std::string &s1, const std::string &s2){
return s1.size() < s2.size();
} #endif /*COUNT_WORD_H*/

最新文章

  1. jQuery中,$(&#39;#main&#39;) 与 document.getElementById(&#39;main&#39;)是什么样的关系-转
  2. fgets函数
  3. python简单实现用户表单登录
  4. 用C#制作PDF文件全攻略
  5. Android虚拟环境的工具集Genymotion完整安装教程
  6. SLua 中使用 Lua 5.3 的编译工程
  7. 基于Minifilter框架的文件过滤驱动理解
  8. UC浏览器 分享到朋友圈和微信好友
  9. 十分钟学会写shell脚本
  10. Python模块之ConfigParser - 读写配置文件
  11. 使用css3实现小菊花加载效果
  12. phpstudy升级mysql数据库
  13. Scrapy命令行基本用法
  14. Linux 修改时间和时区为上海时区
  15. visio子流程创建
  16. tab------左右布局
  17. day1-windows下python和selenium的安装
  18. OneNet平台初探成功
  19. Java解决LeetCode72题 Edit Distance
  20. 微信小程序之tabbar切卡

热门文章

  1. Nginx为什么比Apache Httpd高效
  2. python核心编程学习记录之正则表达式
  3. 利用yarn多队列实现hadoop资源隔离
  4. Jquery.data()的值存放再什么地方的问题?
  5. javascript event loop
  6. Node.js 使用jQuery取得Nodejs http服务端返回的JSON数组示例
  7. Velocity.js动画库使用
  8. Java Learning Path(三)过程篇
  9. curl测试Docker容器连通性
  10. &amp;lt;!DOCTYPE&amp;gt;奇葩的问题