1071. Speech Patterns (25)
来源:互联网 发布:d3.js 4.1中文api文档 编辑:程序博客网 时间:2024/06/06 08:56
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用map建立键值对
把能组成一个单词的找出来,然后map++;
#include<cstdio>#include<cmath>#include<algorithm>#include<iostream>#include<cstring>#include<map>using namespace std;int pd(char s){if((s>='A'&&s<='Z')||(s>='a'&&s<='z')||(s>='0'&&s<='9')) return 1;return 0;}int main(){char s[1048576+10];map<string,int> m;gets(s);int len=strlen(s);int num=0;string out="";for(int i=0;i<len;i++){if(s[i]>='A'&&s[i]<='Z') s[i]+=32;}//cout<<s<<endl;for(int i=0;i<len;){if(pd(s[i])){char fz[10000];int cnt=0;string f="";for(;i<len&&pd(s[i]);i++){f+=s[i];//cout<<s[i];}//cout<<" ";//cout<<f<<endl;m[f]++;if(m[f]>num){num=m[f];out=f;}}else i++;}cout<<out<<" "<<num;return 0;}
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- Listview和其他滑动控件嵌套使用的坑
- [RK3288][Android6.0] 主动从WLAN网络切换到移动数据网络
- Android 通过scheme跳转界面
- [Linux]常用命令与目录全拼
- 中石油 暑期集训个人赛 水题部分
- 1071. Speech Patterns (25)
- spring-boot与mybatis结合
- Activity四种启动模式
- logstash——redis读取脚本
- 干货收集
- 自定义一个图片加文字button,点击有效果
- 杨辉三角
- 如何做练习更能提升自己
- 6.2面向对象(Math类,成员方法,代码块,继承,制作文档说明书)