[CareerCup] 17.9 Word Frequency in a Book 书中单词频率
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] 17.9 Word Frequency in a Book 书中单词频率的更多相关文章
- [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 ...
- Individual Project - Word frequency program-11061171-MaoYu
BUAA Advanced Software Engineering Project: Individual Project - Word frequency program Ryan Mao (毛 ...
- Word Frequency
https://leetcode.com/problems/word-frequency/ Write a bash script to calculate the frequency of each ...
- [Bash]LeetCode192. 统计词频 | Word Frequency
Write a bash script to calculate the frequency of each word in a text file words.txt. For simplicity ...
- LeetCode(192. Word Frequency)
192. Word Frequency Write a bash script to calculate the frequency of each word in a text file words ...
- 使用word和pdf进行仿书编辑的经验
一.问题的提出: 一本书扫描好,要将书中的图片转换为文字版的word文档.二.问题的分析: 1.文字的提取 2.文字的编排三.问题的解决 1.如果用的是Adobe Acroba ...
- 教您如何在Word的mathtype加载项中修改章节号
在MathType数学公式编辑器中,公式编号共有五部分内容:分别是章编号(Chapter Number).节编号(Section Number).公式编号(Equation Number).括号(En ...
- 【LeetCode】211. Add and Search Word - Data structure design 添加与搜索单词 - 数据结构设计
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 公众号:负雪明烛 本文关键词:Leetcode, 力扣,211,搜索单词,前缀树,字典树 ...
- [CareerCup] 17.14 Unconcatenate Words 断词
17.14 Oh, no! You have just completed a lengthy document when you have an unfortunate Find/Replace m ...
随机推荐
- 【荐】Spring事务配置的五种方式
Spring配置文件中关于事务配置总是由三个组成部分,分别是DataSource.TransactionManager和代理机制这三部分,无论哪种配置方式,一般变化的只是代理机制这部分. DataSo ...
- 强化的单例属性_Effective Java
Singleton指的是仅仅被实例化一次的类,比如唯一的系统组件等,成为Singleton的类测试起来也比较困难. 常用的方法: 1.公有静态final域+私有构造器 public class Egg ...
- Codeforces Round #369 (Div. 2) C. Coloring Trees DP
C. Coloring Trees ZS the Coder and Chris the Baboon has arrived at Udayland! They walked in the pa ...
- MarkupExtension
目的 如果要在XAML里引用静态或动态对象实例,或在XAML中创建带有参数的类.这时,我们需要用到XAML扩展.XAML扩展常用来设定属性值.使用标识扩展,告诉 XAML 处理不要像通常那样将属性值 ...
- 遍历进程活动链表(ActiveProcessLinks)、DKOM隐藏进程
1.EPROCESS结构体 EPROCESS块来表示.EPROCESS块中不仅包含了进程相关了很多信息,还有很多指向其他相关结构数据结构的指针.例如每一个进程里面都至少有一个ETHREAD块表示的线程 ...
- 出来ios顶部导航掉下来问题
<script type="text/javascript"> setposition(); function setposition(){ var ua = navi ...
- 【JS】两种计时器/定时器
1.首先介绍定时器 定时器:设置一个定时器,再设置一个等待的时间,到达指定时间后,执行对应的操作 两种定时器:用法一样,区别一个执行后不会停下来,一个只执行一次 第一种:window.setInter ...
- 【maven 报错】maven项目执行maven install时报错Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode)
在使用maven新建的web项目中,执行 执行如上的这两个操作,报错: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-co ...
- hdu3448 01背包+dfs
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=3448 Description 0/1 bag problem should sound f ...
- HTML5 重要标签及其属性学习
1.google字体:<link href="https://fonts.googleapis.com/css?family=Lobster" rel="style ...