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. PMP 第十三章 项目干系人管理

    1.识别干系人是干什么?早期就识别干系人的原因是什么?识别干系人的输入和工具有哪些?干系人分析的几种模型是哪些?干系人登记册的内容有哪些?bbs.mypm.net 2.干系人参与程度的分类是怎样的?干 ...

  2. Sublime Text3 配置Node.js运行命令

    ­ 在Sublime Text中可以很容易配置新的编译运行命令,下面的截图是汉化版的中文菜单,英文菜单请直接对照. 首先需要在本地安装Node,默认的Node会加入到系统的环境变量,这样执行Node命 ...

  3. linux下的c编程

    linux下的c编程 Linux 系统上可用的 C 编译器是 GNU C 编译器, 它建立在自由软件基金会的编程许可证的基础上,因此可以自由发布.GNU  C 对标准 C 进行一系列扩展,以增强标准 ...

  4. 去除字符串中的html标记及标记中的内容

    去除字符串中的html标记及标记中的内容 --1.创建函数 create function [dbo].[clearhtml] (@maco varchar(8000)) returns varcha ...

  5. sql 提取数字、字母、汉字

    --提取数字 IF OBJECT_ID('DBO.GET_NUMBER2') IS NOT NULL DROP FUNCTION DBO.GET_NUMBER2 GO )) ) AS BEGIN BE ...

  6. 在MySQL中存储大文件

    我们的目标:把一首mp3保存到MySQL数据库中! 由于MySQL默认当存入的数据太大时会抛异常,所以应在my.ini中添加如下配置!max_allowed_packet=10485760,这样,可以 ...

  7. POJ 3067 Japan(经典树状数组)

    基础一维树状数组  题意:左边一排 1-n 的城市,右边一排 1-m 的城市,都从上到下依次对应.接着给你一些城市对,表示城市这两个城市相连,最后问你一共有多少个交叉,其中处于城市处的交叉不算并且每个 ...

  8. John the Ripper

    John the RipperJohn the Ripper(简称John)是一款著名的密码破解工具.它主要针对各种Hash加密的密文.它不同于Rainbow Table方式.它采用实时运算的方式和密 ...

  9. Java数组课后作业

    1.运行TestArrays.java,了解Arrays中的一些重要方法的用法. Arrays.equals(a 1, a2):判断数组是否相等. int[] b = Arrays.copyOf(a, ...

  10. Codeforce 493c

    H - Vasya and Basketball Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & ...