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 ...
随机推荐
- excel数据复制到html表格<textarea>中
方案一 多行文本框接收到复制的excel值后,在文本框的chage事件中,将excel内容分割到二维数组中,然后填充到html的表格的input或textarea中. 数据格式: 单元格复制后的数据格 ...
- datepicker动态初始化
datepicker 初始化动态表单的input,需要调用jquery的on方法来给未来元素初始化. //对动态添加的时间文本框进行动态初始化 $('table').on("focus&qu ...
- c# Parallel.For 并行编程 执行顺序测试
因为有个for 实际执行结果尽管是按照for里边的顺序执行,但处理器让哪个分线程先执行,谁先处理完就不一定了. 对于要求结果需要先后顺序的,比如对text内容的操作, 用并行 Parallel.For ...
- Android开发之自定义的ProgressDialog
package com.example.dialog; import android.app.ProgressDialog; import android.content.Context; /** * ...
- Github上Markdown基本语法
基础写作和语法格式 本篇文章的内容来源于Github的基础写作帮助.如果在观看时有什么问题,可以直接查阅源文件.另外需要说明的是Git对Markdown的支持增加了一些扩展功能,因此在Git上可以渲染 ...
- Luogu 1764 翻转游戏 - 枚举 + 搜索
题目描述 kkke在一个n*n的棋盘上进行一个翻转游戏.棋盘的每个格子上都放有一个棋子,每个棋子有2个面,一面是黑色的,另一面是白色的.初始的时候,棋盘上的棋子有的黑色向上,有的白色向上.现在kkke ...
- Hive 系列(二)权限管理
Hive 系列(二)权限管理 一.关于 Hive Beeline 问题 启动 hiveserver2 服务,启动 beeline -u jdbc:hive2:// 正常 ,启动 beeline -u ...
- Proxmox Reset Root Password
http://c-nergy.be/blog/?p=1777 Step 1 – Boot your Proxmox VE machine. In the boot menu screen, you s ...
- Windows-universal-samples学习笔记系列三:Navigation
Navigation Back Button Master/detail Navigation menu (XAML) Pivot Projection XHR, handling navigatio ...
- NOIP训练测试3(2017081601)
上一波题还是比较水的吧?[?????] 也许吧! 但时间还是比较紧的,所以我从2.5个小时延长至3个小时了. 不管了,做题不能停,今天继续测试. 水不水自己看,我什么也不说(zhe shi zui h ...