People often have a preference among synonyms of the same word. For example, some may prefer "the police", while others may prefer "the cops". Analyzing such patterns can help to narrow down a speaker's identity, which is useful when validating, for example, whether it's still the same person behind an online avatar.

Now given a paragraph of text sampled from someone's speech, can you find the person's most commonly used word?

Input Specification:

Each input file contains one test case. For each case, there is one line of text no more than 1048576 characters in length, terminated by a carriage return \n. The input contains at least one alphanumerical character, i.e., one character from the set [0-9 A-Z a-z].

Output Specification:

For each test case, print in one line the most commonly occurring word in the input text, followed by a space and the number of times it has occurred in the input. If there are more than one such words, print the lexicographically smallest one. The word should be printed in all lower case. Here a "word" is defined as a continuous sequence of alphanumerical characters separated by non-alphanumerical characters or the line beginning/end.

Note that words are case insensitive.

Sample Input:

Can1: "Can a can can a can?  It can!"

Sample Output:

can 5

切记,在遍历的时候,要把最后一个数值加上去

#include <iostream>
#include <unordered_map>
using namespace std;
int main()
{
unordered_map<string,int> mmap;
string str;
getline(cin,str);
string tmp="";
for(int i=;i<str.length();i++) {
str[i]=tolower(str[i]);
if(isalnum(str[i])) tmp+=str[i];
else {
if(tmp!="") mmap[tmp]++;
tmp="";
}
}
if(tmp!="") mmap[tmp]++;
string res;int coun=;
for(auto it=mmap.begin();it!=mmap.end();it++)
if(it->second>coun){
coun=it->second;
res=it->first;
}
cout<<res<<" "<<coun;
return ;
}

PAT Advanced 1071 Speech Patterns (25 分)的更多相关文章

  1. PAT 甲级 1071 Speech Patterns (25 分)(map)

    1071 Speech Patterns (25 分)   People often have a preference among synonyms of the same word. For ex ...

  2. 【PAT甲级】1071 Speech Patterns (25 分)(getline(cin,x))

    题意: 输入一行字符串,输出出现过次数最多的由字母和数字组成的字符串以及它出现的次数(对大小写不敏感,输出全部输出小写). AAAAAccepted code: #define HAVE_STRUCT ...

  3. PAT Advanced 1020 Tree Traversals (25 分)

    1020 Tree Traversals (25 分)   Suppose that all the keys in a binary tree are distinct positive integ ...

  4. PAT (Advanced Level) 1071. Speech Patterns (25)

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

  5. 1071 Speech Patterns (25)(25 分)

    People often have a preference among synonyms of the same word. For example, some may prefer "t ...

  6. PAT甲题题解-1071. Speech Patterns (25)-找出现最多的单词

    分割字符串的用法+map映射给出input中出现次数最多的单词,如果次数相同,给出按字典序最小的. 这里我用了自定义分隔符来读取字符串,方法如下: //按照定义的分隔符d来分割字符串,对str进行读取 ...

  7. 1071. Speech Patterns (25)

    People often have a preference among synonyms of the same word. For example, some may prefer "t ...

  8. A1071 Speech Patterns (25 分)

    一.技术总结 开始拿到这道题目时,思考的是我该如何区分它们每一个单词,不知道这里还是要学习得知在cctype头文件中有一个函数用于查看是否为0~9.a~z.A~Z,就是isalnum(),又因为题目中 ...

  9. PAT Advanced 1154 Vertex Coloring (25 分)

    A proper vertex coloring is a labeling of the graph's vertices with colors such that no two vertices ...

随机推荐

  1. charles 高级批量请求

    本文参考:charles 高级批量请求 这个我感觉有点鸡肋,真正的批量请求,推荐使用JMter charles 高级批量请求就是下面这种简单的设置的 简单的使用还是可以的; 比如简单的测试下,向某一个 ...

  2. Egret入门学习日记 --- 第十一篇(书中 4.1~4.6节 内容)

    第十一篇(书中 4.1~4.6节 内容) 好了,到了这篇开始,前三章都记录完了. 接下来就是到第四章了. 4.1节 的内容总结一下重点: 1.resource目录下default.res.json文件 ...

  3. 不用第三方软件–一键开关笔记本电脑wifi热点的批处理

    笔者有点洁癖啊,很强烈抵制那些辣鸡流氓软件的.用笔记本开个wifi还要装东西,搞不好给我塞一堆东西,我勒个fdkshgkhalsh,. 下面就是集设置密码与开关wifi于一身的bat,这个批处理能简化 ...

  4. Nginx基本使用方法

    原帖:http://zyjustin9.iteye.com/blog/2017394 相信很多人都听过nginx,这个小巧的东西慢慢地在吞食apache和IIS的份额.那究竟它有什么作用呢?可能很多人 ...

  5. Leetcode739 - Daily Temperatures

    题目描述 Leetcode 739 本题考察了栈的使用.题目输入是一段温度值列表,然后返回一个列表.这个列表包含了输入列表中每一天还有多少天温度升高.如果未来没有升高的情况,则输入 0. # Exam ...

  6. 三个思路解决413 Request Entity Too Large报错处理

    最近一个项目当中,要求上传图片,并且限制图片大小,虽然在laravel当中已经添加了相关的表单验证来阻止文件过大的上传,然而当提交表单时,还没轮到laravel处理,nginx就先报错了.当你仔细看报 ...

  7. Soda Machine【差分+离散化】

    题目链接:https://ac.nowcoder.com/acm/contest/1106/A 题目大意: 1.一条长1e9的线段,每个节点都可以上色.给出n次操作,每次操作将[l, r]区间内的节点 ...

  8. Eureka如何剔除已经宕机的节点

    同一个服务部署了多个实例,在通过网关调用时会随机调用其中一个.但是,当某个服务挂掉之后,依然在注册中心中,依然会随机被调用到,调用时便会超时报错.(主要是开发测试或者演示时需要立即将失效的从注册中心剔 ...

  9. Redis学习笔记(一):Redis的数据类型

    之前笔者常常接触的数据库是关系型数据库,其中MySQL接触居多.近年来NoSQL兴起,各种新型数据库不断诞生,redis就是NoSQL中的一种热门数据库. 注:此类文章仅仅作为笔者的学习和阅读积累,若 ...

  10. VC++:创建,调用Win32静态链接库

    概述 DLL(Dynamic Linkable Library)动态链接库,Dll可以看作一种仓库,仓库中包含了可以直接使用的变量,函数或类. 仓库的发展史经历了"无库" ---& ...