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 ...
随机推荐
- Linux服务正常启动,Linux服务器能访问,但是外部机器不能访问
公司用到了jenkins,就在自己虚拟机里面部署了一个jenkins.部署成功之后,在Linux虚拟机里面能正常访问,但是外部真实机却不能访问.当时的第一反应就是觉得应该是权限问题,猜测会不会是jen ...
- UVA1626 括号序列 Brackets sequence(区间dp)
题目传送门(洛谷) 题目传送门(UVA) 解题思路 很显然是一个区间dp,当然记忆化搜索完全可以AC,这里说一下区间dp. 区间dp的重要特征就是需要枚举中间节点k 看一看这道题,用f[i][j] ...
- flex布局解说和属性
1. flex-direction 规定当前DIV下面的子元素是横向布局还是纵向布局 row 默认值,横向布局相当于float:left column 纵向,相当于DIV默认的垂直方向 2.justi ...
- 洛谷 - P3803 - 【模板】多项式乘法(FFT) - FFT
https://www.luogu.org/problemnew/show/P3803 用反向学习的FFT通过这个东西. #include <bits/stdc++.h> using na ...
- [转]java web 文件上传
实现WEB开发中的文件上传功能,需完成如下二步操作: 在WEB页面中添加上传输入项,<input type=“life” name=“”>,使用时注意: 1. 必须要设置 ...
- JavaScript 各种遍历方式详解及总结
JavaScript 各种遍历方式详解 在$.each中想要终止循环,但是它没有continue或者break这样的终止方式,所以尝试使用return来进行终止,但是发现并没有跳出循环.为了搞清楚js ...
- CSS语法规则
一.At-rule 一种以@开头的声明语句,以分号;结尾.语法规则为: @IDENTIFIER (RULE); . At-rule主要用作表示CSS的行为,参考: https://www.cnblog ...
- 解决java compiler level does not match the version of the installed java project facet问题
在编写项目的时候是,后来有改java写法,将工程改成了jdk1.7,后来工程就有了一个红叉,但是代码,文件里没有任何问题,也可以运行,不知道是什么原因,后来在problems里才知道是:java co ...
- python控制cpu使用率
以下亲测可行. 使用方法:命令行模式 runing.py -c 2 -t 0.01 -c 指定cpu核数:不指定-c参数默认为所有核数. -t 数值越大,cpu使用率越低. runing.py &qu ...
- 吉首大学2019年程序设计竞赛(重现赛) B 干物妹小埋
链接:https://ac.nowcoder.com/acm/contest/992/B来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536K ...