Speech Patterns
来源:互联网 发布:http 文件 json 上传 编辑:程序博客网 时间:2024/06/16 10:14
1071. Speech Patterns (25)
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
#include<cstdio>#include<map>#include<iostream>#include<cctype>#include<string>using namespace std;map<string,int> mp;string word;void trans(string &s){for(int i=0;i<s.size();i++){char ch=s[i];if(isalnum(ch)){ch=tolower(ch);word+=ch;}else{if(!word.empty())mp[word]++;word.clear();}}if(!word.empty())mp[word]++;}int main(){int Max=-1;string s,lower;getline(cin,s);trans(s);map<string,int> ::iterator ie=mp.end();for(map<string,int> ::iterator it=mp.begin();it!=ie;it++){int sec=it->second;string fir=it->first;if(sec>Max){lower=fir;Max=sec;}else if(sec==Max){if(lower>fir)lower=fir;}}cout<<lower<<' '<<Max;return 0;}
- Speech Patterns
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns
- 1071. Speech Patterns (25)
- 1071. Speech Patterns
- PAT 1071. Speech Patterns
- 1071. Speech Patterns
- 1071. Speech Patterns (25)
- PAT 1071 Speech Patterns
- PAT 1071. Speech Patterns
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071.Speech Patterns
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns
- 1071. Speech Patterns (25)
- java中有关Frame背景的设置总结
- springmvc常用注解标签详解
- 八大排序算法总结
- MySQL忘记密码
- webrtc百度网盘下载与windows平台编译错误解决
- Speech Patterns
- scrapy入门
- RabbitMQ官方中文入门教程(PHP版) 第三部分:发布/订阅(Publish/Subscribe)
- 【C语言】移位运算符、位运算符、逻辑运算符
- 51Nod-1091-线段的重叠
- rhel与aix中,fsck -f的区别
- pyhton3正则表达式应用(面试题)
- beego利用casbin进行权限管理——第二节 策略存储
- RabbitMQ官方中文入门教程(PHP版) 第四部分:路由(Routing)