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. 转载【oracle切换表空间】

    http://blog.itpub.net/28939273/viewspace-1061476/ [root@yoon ~]# more /etc/oracle-releaseOracle Linu ...

  2. oracle jdk和openjdk区别;idea如何加载jdk源码并调试jdk代码

    两个jdk的区别 oracle jdk是sun/oracle(甲骨文)公司的,部分jdk开源:相对比较稳定,使用的比较多. openjdk是完全开源的,据说是官方oracle唯一承认的开源版本. id ...

  3. 【数据库开发】在Windows上和Linux上配置MySQL的过程

    [数据库开发]在Windows上和Linux上配置MySQL的过程 标签(空格分隔): [编程开发] 首先是在Windows上尝试用QT进行MySQL数据库开发,结果总出现driver不能load的错 ...

  4. Ie浏览器请求400错误,谷歌火狐等浏览器正常请求.

    做项目的时候,遇到一个小的问题.一个location.href="请求的url"在其它浏览器上是可以正常请求的.但是在ie浏览器上确出现奇怪的http请求400错误,我们先来对于h ...

  5. Nginx+PHP(FastCGI)高性能服务器加载redis+memcache模块

    1)Nginx+FastCGI安装配置: yum install  openssl openssl-devel pcre-devel pcre zlib zlib-devel –y #下载Nginx源 ...

  6. Python爬虫入门教程之BeautifulSoup

    模块安装 pip3 install beautifulsoup4 模块导入 from bs4 import BeautifulSoup 示例html内容 RPC是一种比较流行的RPC通信框架,由谷歌公 ...

  7. sql中能使用charindex 不要用 in 。charindex比in快很多

    写SQL语句我们经常需要判断一个字符串中是否包含另一个字符串,但是SQL SERVER中并没有像C#提供了Contains函数,不过SQL SERVER中提供了一个叫CHAEINDX的函数,顾名思义就 ...

  8. 多个结果集union后保持各自原有排序

    SELECT *FROM ( SELECT TOP (@count1) a.* FROM Article AS a WITH (NOLOCK)LEFT JOIN Article_Type AS at ...

  9. SQL SERVER 实现多行转多列

    有这样一个需求,一个表单主表,一个扩展列表,查询的时候要把扩展列表中的多行转成主表多列. 比如 dt_zhubiao [主表] id type title 1 1 表单1-1 2 1 表单1-2 3 ...

  10. Linux下安装redis 3.0及C语言中客户端实现demo

    1.获取安装文件 wget http://download.redis.io/redis-stable.tar.gz 2.解压文件 tar xzvf redis-stable.tar.gz 3.进入目 ...