#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*/

统计输入的单词中有几个长度大于n的,n是自己指定的,用函数对象实现的更多相关文章

  1. C 循环统计输入的单词个数和字符长度

    C 循环统计输入的单词个数和字符长度 #include <stdio.h> #include <Windows.h> int main(void) { ]; ; ; print ...

  2. c程序设计语言_习题1-13_统计输入中单词的长度,并且根据不同长度出现的次数绘制相应的直方图

    Write a program to print a histogram of the lengths of words in its input. It is easy to draw the hi ...

  3. C 统计用户输入的总行数和字符长度

    C 统计用户输入的总行数和字符长度 #include <stdio.h> #include <Windows.h> int main(void) { ]; ; ; printf ...

  4. asp.net——统计输入的字符数目

    asp.net——统计输入的字符数目 题目: 在页面中有一个TextBox输入框,一个显示文字用的Label,一个提交按钮Button.在TextBox中输入一段英文字母,点击按钮提交后统计其中字母‘ ...

  5. 已知一个字符串S 以及长度为n的字符数组a,编写一个函数,统计a中每个字符在字符串中的出现次数

    import java.util.Scanner; /** * @author:(LiberHome) * @date:Created in 2019/3/6 21:04 * @description ...

  6. 写一个函数,求一个字符串的长度,在main函数中输入字符串,并输出其长度

    import java.util.Scanner; /** * [程序38] * * 题目:写一个函数,求一个字符串的长度,在main函数中输入字符串,并输出其长度. * * @author Jame ...

  7. C# 使用js正则表达式,让文本框只能输入数字和字母,最大长度5位

    使用js正则表达式,让文本框只能输入数字和字母,最大长度5位,只需要加个onkeyup事件,即可简单实现 <asp:TextBox ID="txtBegin" runat=& ...

  8. PHP统计字符串里单词查询关键字

    <?function full_count_words($str) {     //返回完整数组,包含字符串里每个单词 $words = str_word_count($str,1);     ...

  9. 输入n个数组,数组长度不等,每个数组取出一个数进行组合,求出所有的组合。

    转载声明:原文转自http://www.cnblogs.com/xiezie/p/5511707.html 昨天晚上,有个朋友找到我,他在用matlab编程,但是遇到一个问题,解决不了. 问题如下: ...

随机推荐

  1. Makefile之文件搜索

    Makefile之文件搜索 1.Makefile 文件中的"VPATH"变量 如果没有指明这个变量,make只会在当前目录下查找依赖文件和目标文件: 如果定义了这个变量,make会 ...

  2. log4j教程 7、日志记录级别

    org.apache.log4j.Level类提供以下级别,但也可以通过Level类的子类自定义级别. Level 描述 ALL 各级包括自定义级别 DEBUG 指定细粒度信息事件是最有用的应用程序调 ...

  3. ElasticSearch refresh API

    在 Elasticsearch 中,写入和打开一个新段的轻量的过程叫做 refresh . 默认情况下每个分片会每秒自动刷新一次.这就是为什么我们说 Elasticsearch 是 近 实时搜索: 文 ...

  4. 小白学react之网页获取微信用户信息

    通过上一篇<小白学react之EJS模版实战>我们学习了怎样通过EJS模版生成我们高定制化的index.html文件. 本篇我们将会继续延续我们的alt-tutorial项目的实战计划.去 ...

  5. iOS---sha1加密的一个坑

    OC语言写的sha1加密算法,在网上随手能够搜索到(例如以下便是),可是我不得不说有一些人不责任,没有提醒大家导入必要的系统头文件.从而导致错误 + (NSString *) sha1:(NSStri ...

  6. TestNG+ReportNG+IDEA+Git+Jenkins+surefire持续集成数据驱动dubbo接口测试

    一.pom.xml增加testng相关配置 <!--添加插件 关联testNg.xml--><plugin> <groupId>org.apache.maven.p ...

  7. vue-router 嵌套路由

    const router = new VueRouter({ routes: [ { path: '/user/:id', component: User, children: [ { // 当 /u ...

  8. document.querySelector()与document.querySelectorAll()

      document.querySelector()与document.querySelectorAll() CreationTime--2018年7月1日10点49分 Author:Marydon ...

  9. Windows web服务器搭建---阿里云

      前提步骤: 1)申请域名---- 阿里云.花生壳.万维网等等. 2)云主机购买-----阿里云.腾讯云.京东云等等. 3)网站备案,此步骤最长. 4)建立网站 5)部署网站 下面主要介绍如何部署网 ...

  10. mysql导出查询结果到文档

    其实挺简单,就一个命令 select * from my_table into outfile '/tmp/abc.xls'; 然后就是ftp把文件弄回本地了.我的是程序自动放到C:\下   另外,还 ...