PAT_A1071#Speech Patterns
Source:
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的更多相关文章
- Pat1071: Speech Patterns
1071. Speech Patterns (25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 HOU, Qiming Peo ...
- 【算法笔记】A1071 Speech Patterns
1071 Speech Patterns (25 分) People often have a preference among synonyms of the same word. For ex ...
- PAT 1071 Speech Patterns[一般]
1071 Speech Patterns (25 分) People often have a preference among synonyms of the same word. For exam ...
- PAT 甲级 1071 Speech Patterns (25 分)(map)
1071 Speech Patterns (25 分) People often have a preference among synonyms of the same word. For ex ...
- 1071 Speech Patterns——PAT甲级真题
1071 Speech Patterns People often have a preference among synonyms of the same word. For example, so ...
- 1071. Speech Patterns (25)
People often have a preference among synonyms of the same word. For example, some may prefer "t ...
- Speech Patterns (string)
People often have a preference among synonyms of the same word. For example, some may prefer "t ...
- A1071. Speech Patterns
People often have a preference among synonyms of the same word. For example, some may prefer "t ...
- 1071 Speech Patterns
People often have a preference among synonyms of the same word. For example, some may prefer "t ...
随机推荐
- 用bootstrap和css3制作按钮式下拉菜单
利用bootstrap框架的字体图标和下拉菜单效果,以及css3的动画效果,可以做出比较优雅的按钮式下拉菜单样式 <style> .myBtnStyle .dropdown-menu sp ...
- [暑假集训Day2T1]种树
标算是贪心,我写了个差分约束????? 设dist[i]表示1-i号土地种的树的总棵数,考虑以下几种约束条件: 1)dist[y]>=dist[x]+z,即x号土地至y号土地间至少种了z棵树 2 ...
- 基于各种基础数据结构的SPFA和各种优化
一.基于各种数据结构的SPFA 以下各个数据均为不卡SPFA的最短路模板:P3371 [模板]单源最短路径(弱化版)的测试时间 1.STL队列:用时: 1106ms / 内存: 8496KB #inc ...
- python常用的时间方法
from time import strftime setTime = strftime("%Y_%m_%d_%H_%M_%S", time.localtime()) // In ...
- mint/ubuntu Android Eclipse ADT 简单安装及执行崩溃解决的方法
1. 下载 Android SDK(ADT Bundle) http://developer.android.com/sdk/index.html (站点訪问不了或者慢.请參考:轻松改 ...
- MyBatis 配置/注解 SQL CRUD 经典解决方案(2019.08.15持续更新)
本文旨在记录使用各位大神的经典解决方案. 2019.08.14 更新 Mybatis saveOrUpdate SelectKey非主键的使用 MyBatis实现SaveOrUpdate mybati ...
- Spring学习笔记(3)——快速入门
项目目录如下: Say.java为主函数通过ApplicationContext创建对象,利用方法ClassPathXmlApplicationContext访问配置文件Applicationcont ...
- 完善Hikari连接池扩展项目HikariApi(ORM)
以前介绍类自定义的Hikari项目,定位于数据库连接池:后扩展了,根据文件名称,以数据库配置文件为基础,支持按照名称多数据操作. 在使用中,发现扩展了SQL语句参数化操作,在管理类中,以扩展方法存在. ...
- github命令大全
github是一种开源的版本控制工具,现在已经得到很多人的应用.所以想介绍一下github的一些使用. github安装 github提供了桌面客户端,我们也可以通过命令行的方式来进行控制. wind ...
- 道路模型--linear-parabolic model
读过很多道路追踪的论文,经常都需要道路模型的建模.我不知道是不是因为自己太笨还是怎样,好多人建的模型我实在无法理解他的用意何在,而且我真的深刻怀疑他们那些模型的参数是不是真的可以求出来.就比如这篇文章 ...