1071 Speech Patterns
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.
字符串相关知识点总结:
·判断是否数字,字母:
#include <cctype>
isnumber(int _c);
isalnum(int _c);
isalpha(int _c);
·大小写转换
#include <cctype>
tolower(int _c);
toupper(int _c);
·字母数字转化
#include <iostream>
#include <sstream>
using namespace std; string s="1234.4";
printf("%f",stof(s)); s="1234";
printf("%d",stoi(s)); a=1234;
cout<<to_string(a);
#include <string>
#include <iostream>
#include <map>
#include <cctype>
using namespace std; int main(){
string input;
map<string,int> Mp; getline(cin, input);
string tmpStr;
for(int i=;i<input.length();i++){
if(isalnum(input[i])){
tmpStr+=tolower(input[i]);
if(i==input.length()-){
Mp[tmpStr]++;
}
}else{
if(tmpStr.length()) Mp[tmpStr]++;
tmpStr.clear();
}
} string max; int maxTimes;
for(map<string,int>::iterator it=Mp.begin();it!=Mp.end();it++){
if(maxTimes<it->second){
maxTimes=it->second;
max=it->first;
}else if(maxTimes==it->second&&max>it->first){
max=it->first;
}
}
cout<<max<<" "<<maxTimes<<endl;
}
1071 Speech Patterns的更多相关文章
- 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 ...
- 1071 Speech Patterns (25)(25 分)
People often have a preference among synonyms of the same word. For example, some may prefer "t ...
- PAT Advanced 1071 Speech Patterns (25 分)
People often have a preference among synonyms of the same word. For example, some may prefer "t ...
- PAT (Advanced Level) 1071. Speech Patterns (25)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- PAT甲题题解-1071. Speech Patterns (25)-找出现最多的单词
分割字符串的用法+map映射给出input中出现次数最多的单词,如果次数相同,给出按字典序最小的. 这里我用了自定义分隔符来读取字符串,方法如下: //按照定义的分隔符d来分割字符串,对str进行读取 ...
- PAT 1071. Speech Patterns
又是考输入输出 #include <cstdio> #include <cstdlib> #include <string> #include <vector ...
随机推荐
- ifconfig 运行command not found
vi /home/lx/.bash_profile中添加 PATH=$PATH:$HOME/bin:/sbin:/bin export PATH linux查看服务自启动 chkconfig - ...
- 配置go语言编辑环境 - goland
快捷键: 移动行 Alt + Shift + up/down 行内(选中)移动(到头尾/删除) Ctrl(Shift) + left/rignt(Home/End/Backspace) 插入新行 Sh ...
- Could not load file or assembly 'Microsoft.EntityFrameworkCore.Relational
提示的很明确了,缺少Microsoft.EntityFrameworkCore.Relational引用.nuget安装上即可.
- if 循环的深入理解 哈希表的一种应用
哈希表的值作为一个颜色容器,值默认为标识1, 表示未曾用过,若用过标识为0: 1: 程序第一步 遍历哈希表,查找标识为1 未曾用过的颜色 我用了这个: string colorno_us ...
- Linux_(4)Shell编程(下)
五.shell流程控制1.一重分支if 语句语法格式:if condition then command1 fi末尾的fi就是if倒过来. 写成一行: if condition; then comma ...
- Oracle_SQL(2) 分组与聚合函数
一.聚合函数1.定义:对表或视图的查询时,针对多行记录只返回一个值的函数.2.用途:用于select语句,HAVING条件二.5种聚合函数1.SUM(n) 对列求和 select sum(sal) f ...
- tableView上出现空白的解决办法
创建tableView后,出现如下效果 解决办法: self.automaticallyAdjustsScrollViewInsets = NO; 个人认为,应该是取消系统默认行为,保证界 ...
- 程序员"装B"手册
一.准备工作 “工欲善其事必先利其器.” 1.电脑不一定要配置高,但是双屏是必须的,越大越好,能一个横屏一个竖屏更好.一个用来查资料,一个用来写代码.总之要显得信息量很大,效率很高. 2.椅子不一定要 ...
- Ubuntu12.04软件安装指南
更新升级源 首先编辑软件源,在终端输入下面命令: sudo gedit /etc/apt/sources.list 较快速的升级源有163,台湾源,科大源,搜狐源等,大家将新的升级源全部覆盖原文件so ...
- Windows 修改的hosts记录没有效果
windows修改的hosts记录没有效果,新添加的也没有效果. 检查DNS设置相关的均正常, <Dns client为此计算机解析和缓冲域名系统 (DNS) 名称.> 为此计算机注册并更 ...