Source:

PAT A1071 Speech Patterns (25 分)

Description:

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

Keys:

  • 字符串处理

Code:

 #include<cstdio>
#include<string>
#include<map>
#include<iostream>
#include<algorithm>
using namespace std;
map<string,int> mp; int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif // ONLINE_JUDGE string s;
getline(cin,s);
transform(s.begin(),s.end(),s.begin(),::tolower);
int i=,j=,cnt=;
while(i<s.size())
{
int j=i;
while(j<s.size() && ((s[j]>=''&&s[j]<='')||(s[j]>='a'&&s[j]<='z')))
j++;
if(j>i)
{
mp[s.substr(i,j-i)]++;
if(mp[s.substr(i,j-i)]>cnt)
cnt = mp[s.substr(i,j-i)];
}
i=j+;
}
for(auto it=mp.begin(); it!=mp.end(); it++)
if(it->second == cnt)
{
printf("%s %d", it->first.c_str(),cnt);
break;
} return ;
}

PAT_A1071#Speech Patterns的更多相关文章

  1. Pat1071: Speech Patterns

    1071. Speech Patterns (25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 HOU, Qiming Peo ...

  2. 【算法笔记】A1071 Speech Patterns

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

  3. PAT 1071 Speech Patterns[一般]

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

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

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

  5. 1071 Speech Patterns——PAT甲级真题

    1071 Speech Patterns People often have a preference among synonyms of the same word. For example, so ...

  6. 1071. Speech Patterns (25)

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

  7. Speech Patterns (string)

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

  8. A1071. Speech Patterns

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

  9. 1071 Speech Patterns

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

随机推荐

  1. python 分析 知乎粉丝数据

    昨天花了一下午写了一个小爬虫,用来分析自己的粉丝数据.这个真好玩!今天帮了群里好多大V也爬了他们的数据.运行速度:每分钟5千粉丝以上.暂时先写成这样,这两天要准备补考,没有时间继续玩这个. 下次要改进 ...

  2. 如何做PPT

    如何做出更漂亮的PPT? 1.文字对齐,PPT字体最好使用微软雅黑,文档最好使用宋体 2.总分总的叙述形式 3.颜色最好使用冷色系,蓝色.灰色.灰蓝色等等 4.每段话中的重点内容标出特殊颜色 5.可使 ...

  3. Redis设计与实现 -- 动态字符串对象(SDS)

    1. 动态字符串( simple dynamic string, SDS) 在 Redis 中,当需要可以被重复修改的字符串时,会使用 SDS 类型 ,而不是 C 语言中默认的 C 字符串类型 .举个 ...

  4. rabbitmq部署安装

    1.安装rabbitmq需要提前安装erlang,相关下载地址:http://www.erlang.org/downloads,需要注意:默认安装的RabbitMQ 监听端口是5672     启动和 ...

  5. ROT13加密和解密

    问题 ROT13(回转13位)是一种简易的替换式密码算法.它是一种在英文网络论坛用作隐藏八卦.妙句.谜题解答以及某些脏话的工具,目的是逃过版主或管理员的匆匆一瞥.ROT13 也是过去在古罗马开发的凯撒 ...

  6. elasticsearch 基础 —— 处理冲突及乐观并发控制

    处理冲突 当我们使用 index API 更新文档 ,可以一次性读取原始文档,做我们的修改,然后重新索引 整个文档 . 最近的索引请求将获胜:无论最后哪一个文档被索引,都将被唯一存储在 Elastic ...

  7. lambda 分组后的count

    var list = stuList.GroupBy(b => b.PersonalId).Select(g => (new { personalId = g.Key, count = g ...

  8. Linux系统常用知识(centos7)

    一.查看系统版本 1.查看linux内核版本 #cat /etc/redhat-release 二.主机名 2.1定义: 静态的(Static hostname):“静态”主机名也称为内核主机名,是系 ...

  9. python爬取“美团美食”汕头地区的所有店铺信息

    一.目的 获取美团美食每个店铺所有的评论信息,并保存到数据库和本地 二.实现步骤 获取所有店铺的poiId 首先观察详情页的url,后面是跟着一串数字的,而这一串数字代表着每个店铺特有的id号,我们称 ...

  10. HTTP协议缓存

    缓存的概念 缓存这个东西真的是无处不在, 有浏览器端的缓存, 有服务器端的缓存,有代理服务器的缓存, 有ASP.NET页面缓存,对象缓存. 数据库也有缓存, 等等. http中具有缓存功能的是浏览器缓 ...