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 ...
随机推荐
- NPOI创建DOCX常用操作
1. 创建文档 XWPFDocument m_Docx = new XWPFDocument(); 2. 页面设置 //1‘=1440twip=25.4mm=72pt(磅point)=96px(像 ...
- Await Async和Thread.waitAll想法?未完待续
[管理员]四九-李冰-修行者(2216529884) 2017/7/3 17:15:12 看着就可以了,这种东西是有使用场景的.并不是你用了就一定有提升的 [管理员]上海-xx科技(lovepoint ...
- PL/SQL的快捷键设置
PL/SQL用来连接Oracle数据库的一种工具,它可以设置快捷方式,以便于我们快速的操作. PL/SQL设置快捷键 tools->Preferences(首选项)->User In ...
- Linux apt-get命令
一.简介 Ubuntu系列系统包管理工具. 二.常用指令 1.查询功能 apt-cache search package 搜索软件包 apt-cache show package 获取包的相关 ...
- button获取验证码60秒倒计时 直接用
__block ; __block UIButton *verifybutton = _GetverificationBtn; verifybutton.enabled = NO; dispatch_ ...
- postfix发信提示 Error: too many connectino from
查看提示,很明显是提示连接数过多导致的. 有提示上面的信息,看提示的IP地址是一个网关的地址,使用netstat -ano|grep ':25'|wc -l 看了下,25端口的连接的IP地址,几乎全是 ...
- 超强干货,11个灰常实用的AI设计小技巧!
11个超级实用的AI设计小技巧!涉及到很多的实用操作,纯干货经验总结,灰常值得收藏,赶快转走学起来吧! 编辑:千锋UI设计
- netstat 查看端口命令
查看特定端口是否启动 netstat -lnp |
- java mail 读取邮件列表,
// 准备连接服务器的会话信息 Properties props = new Properties(); props.setProperty("mail.store.protocol&quo ...
- Java,JavaScript,jQuery,jSP,js
js是javascript文件的文件后缀,就像 a.txt 这个.txt是后缀一样 jsp是jsp网页文件的后缀,而jsp是java web 的表现层的一种技术 jquery 是一个函数库,基于jav ...