17.9 Design a method to find the frequency of occurrences of any given word in a book.

这道题让我们找书中单词出现的频率,那么首先需要搞清楚的问题是,只需要统计一个单词,还是多个单词。如果是一个单词的话,那直接就遍历所有单词直接统计即可,如果是多个,就需要建立哈希表来建立每个单词和其出现次数之间的映射,然后再来查找即可,参见代码如下:

unordered_map<string, int> make_dictionary(vector<string> book) {
unordered_map<string, int> res;
for (auto word : book) {
for (auto &a : word) a = tolower(a);
++res[word];
}
return res;
} int get_frequency(unordered_map<string, int> m, string word) {
if (m.empty() || word.empty()) return -;
for (auto &a : word) a = tolower(a);
return m[word];
}

CareerCup All in One 题目汇总

[CareerCup] 17.9 Word Frequency in a Book 书中单词频率的更多相关文章

  1. [CareerCup] 17.4 Maximum of Two Numbers 两数中的较大值

    17.4 Write a method which finds the maximum of two numbers. You should not use if-else or any other ...

  2. Individual Project - Word frequency program-11061171-MaoYu

    BUAA Advanced Software Engineering Project:  Individual Project - Word frequency program Ryan Mao (毛 ...

  3. Word Frequency

    https://leetcode.com/problems/word-frequency/ Write a bash script to calculate the frequency of each ...

  4. [Bash]LeetCode192. 统计词频 | Word Frequency

    Write a bash script to calculate the frequency of each word in a text file words.txt. For simplicity ...

  5. LeetCode(192. Word Frequency)

    192. Word Frequency Write a bash script to calculate the frequency of each word in a text file words ...

  6. 使用word和pdf进行仿书编辑的经验

    一.问题的提出:    一本书扫描好,要将书中的图片转换为文字版的word文档.二.问题的分析:    1.文字的提取    2.文字的编排三.问题的解决    1.如果用的是Adobe Acroba ...

  7. 教您如何在Word的mathtype加载项中修改章节号

    在MathType数学公式编辑器中,公式编号共有五部分内容:分别是章编号(Chapter Number).节编号(Section Number).公式编号(Equation Number).括号(En ...

  8. 【LeetCode】211. Add and Search Word - Data structure design 添加与搜索单词 - 数据结构设计

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 公众号:负雪明烛 本文关键词:Leetcode, 力扣,211,搜索单词,前缀树,字典树 ...

  9. [CareerCup] 17.14 Unconcatenate Words 断词

    17.14 Oh, no! You have just completed a lengthy document when you have an unfortunate Find/Replace m ...

随机推荐

  1. Eclipse+CDT+GDB调试android NDK程序(转)

    Eclipse+CDT+gdb调试android ndk程序 先介绍一下开发环境,在这个环境下,up主保证是没有问题的. ubuntu 11.10 eclipse 3.7(indego) for ja ...

  2. HDU 3727 Jewel 可持久化线段树

    Jewel Problem Description   Jimmy wants to make a special necklace for his girlfriend. He bought man ...

  3. js日期格式化

    <html> <head> <script> function test(){ //Js获取当前日期时间及其它操作 var myDate = new Date(); ...

  4. Hibernate的持久化类状态

    Hibernate的持久化类状态 持久化类:就是一个实体类 与 数据库表建立了映射. Hibernate为了方便管理持久化类,将持久化类分成了三种状态. 瞬时态 transient (临时态):持久化 ...

  5. Android Fragment学习笔记(二)----Fragment界面添加和管理

    Fragment界面添加 了解过fragment的生命周期等简单知识,于是去看官方文档来了解更多相关内容,要添加fragment到我们的UI界面中,给出了两种常用的方法,第一个是在activity的布 ...

  6. PHP入门 - - 05-->编写HTML页面的常用标签

    一.文字版面的编辑 1.格式标签 格式标签用于定义网页中文本的布局.缩进.位置.换行.列表等          <br>           换行          <p>   ...

  7. Android学习系列(42)--Android Studio实战技巧

    使用android studio开发项目的一些问题,功能和技巧. 1. 环境 Mac OSX 10.9.5 + Android Studio 0.8.9 2. gradle项目加载超慢 这是因为gra ...

  8. poj1061 Exgcd

    #include<iostream> #include<cstdio> #include<algorithm> #include<cmath> usin ...

  9. iOS 原生网络请求(推荐使用AFNetWorking库)

    .     同步GET请求       //第一步,创建URL       NSURL *url = [NSURL URLWithString:@"http://api.hudong.com ...

  10. mvn exec用法,运行jar后台驻留进程

    java工程如果打包成war,那依赖的jar包都会被包含进去. 不过如果开发java的后台驻留进程,那一般会打包成jar包的形式,要想在运行进程的时候找到所有的依赖包,基本有如下两种方式: 方式一: ...