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 ...
随机推荐
- node.js中对同步,异步,阻塞与非阻塞的理解
我们都知道javascript是单线程的,node.js是一个基于Chrome V8 引擎的 javascript 运行时环境,注意 node.js 不是一门语言,别搞错了. javascript为什 ...
- 百度 echarts
插件地址:http://echarts.baidu.com/index.html ECharts 特性 特性 丰富的可视化类型 多种数据格式无需转换直接使用 千万数据的前端展现 移动端优化 多渲染方案 ...
- python multiprocessing 和tcp
#用类方法 服务端 from socket import *from multiprocessing import Processimport os class Myprocess(Process): ...
- PopupWindow与Edittext结合使用所遇到的坑
PopupWindow与Edittext结合使用一起实现目的:既可以编辑输入想要的内容,还可以通过下拉列表来实现内容的选择. 我就是这样的一个目的,结果很简单的目的却遇到了很大的坑,下面我将把我遇到的 ...
- 右手坐标系下LookAt视图矩阵的推导
基本知识 右手坐标系 右手手掌弯曲,手指方向由正X轴指向正Y轴,如果这时Z轴正方向与大拇指方向保持一致,坐标系为右手坐标系,否则为左手坐标系. 向量叉乘的方向 向量(1,0,0)与向量(0,1,0)叉 ...
- vs视图引入命名空间设置方法
解决: 1.@using在cshtml的最上面,加上一句: @using Puzzle.Framework.Common 2.在View文件夹下面的web.config里面加: <system. ...
- BZOJ1057或洛谷1169 [ZJOI2007]棋盘制作
BZOJ原题链接 洛谷原题链接 设\(L[i][j],R[i][j],H[i][j]\)表示点\((i,j)\)向左.右.上尽量拓展的左端点.右端点.上端点的坐标. \(L,R\)直接初始化好,\(H ...
- 卸载服务器GitLab
sudo gitlab-ctl uninstall sudo rpm -e gitlab-ce find / -name gitlab|xargs rm -rf
- APP强制退出
第一种方法: 企业版可以用,Appstore可能被拒,慎用 - (void)exitApplication { AppDelegate *app = [UIApplication sharedAppl ...
- Luogu 3620 数据备份 - Set
Solution 很显然, 最优情况肯定是相邻两个相连 . 然后模型就跟 Luogu1484 类似了. 把两个房子 看成一个坑 (参考 Luogu1484), 选取 $k$ 个不相邻的坑, 使得权值最 ...