[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 ...
随机推荐
- 3D建模与处理软件简介
[前言]自半年前笔者发表博客“什么是计算机图形学”以来,时常有人来向笔者询问3D模型的构建方法与工具.笔者的研究方向是以3D技术为主,具体包括3D建模,3D处理及3D打印三个方面,在3D建模与处理方面 ...
- Git 基础操作
[TOC] 在Linux上安装Git $ git --version #查看git的版本号 $ sudo apt-get install git # 安装git 创建版本库 $ git init # ...
- Codeforces Round #276 (Div. 1) E. Sign on Fence 二分+主席树
E. Sign on Fence Bizon the Champion has recently finished painting his wood fence. The fence consi ...
- BZOJ 2152: 聪聪可可 树分治
2152: 聪聪可可 Description 聪聪和可可是兄弟俩,他们俩经常为了一些琐事打起来,例如家中只剩下最后一根冰棍而两人都想吃.两个人都想玩儿电脑(可是他们家只有一台电脑)……遇到这种问题,一 ...
- JDBC之——一个单线程JDBC基类和一些注意事项
下面的一个DBase基类提供了一些jdbc的基本操作,配置文件的配置部分并不准确,只是在自己机器上的mysql中测试过.. 数据库的增删改方法中都在开始调用了getConnection方法,末尾调用了 ...
- 聊聊传统oo和js的某些对比——对象/函数/new关键字等
自己的学习记录,写的短点可以以后短时间内理清一些疑惑,看前要求你至少了解js中关于原型链等基本概念,因为文章直接以总结的形式理出知识点,没有去解释一些基本的概念! 1.1.熟记两句话,预预热 1. 函 ...
- sidt十六进制代码
00121453 0F010D 40441200 sidt fword ptr ds:[gliu]0012145A 0F014D B0 sidt fword ptr ss:[ebp-0x50]0012 ...
- 图说设计模式(UML和设计模式)
https://github.com/me115/design_patterns http://design-patterns.readthedocs.org/zh_CN/latest/index.h ...
- Java学习笔记(七)——对象
一.类与对象 1.类的定义 类就是模型,确定对象将会拥有的特征(属性)和行为(方法). 2.类的特点 (1)类是对象的类型 (2)具有相同属性和方法的一组对象的集合. 3.对象的属性: 对象具有的各种 ...
- css3设置边框属性
css设置边框属性:设置边框圆角 <!DOCTYPE html> <html> <head lang="en"> <meta charse ...