博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
1071. Speech Patterns (25)
阅读量:4333 次
发布时间:2019-06-07

本文共 2133 字,大约阅读时间需要 7 分钟。

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的用法。
#include
#include
#include
#include
#include
using namespace std;map
mp;vector
v;bool legal(int i){ char c = v[i]; if(c>='A'&&c<='Z'){ v[i]=c-'A'+'a'; return true; }else if(c>='a'&&c<='z'){ return true; }else if(c>='0'&&c<='9'){ return true; }else{ return false; }}int main(){ char ch; while(scanf("%c",&ch)){ v.push_back(ch); if(ch=='\n'){ break; } } int len=v.size(); int tmp=0; int s=0,d=0; int max=-1; vector
::iterator it = v.begin(); for(int i=0;i
max){ max=mp[ss]; } d++; s=d; continue; } s = d = i+1; } map
::iterator ite = mp.begin(); for(;ite != mp.end();ite++){ if(ite->second == max){ //printf("%s %d\n",ite->first,ite->second); cout<
first<<' '<
second<

  

转载于:https://www.cnblogs.com/grglym/p/7867283.html

你可能感兴趣的文章
Hadoop以及组件介绍
查看>>
1020 Tree Traversals (25)(25 point(s))
查看>>
第一次作业
查看>>
“==”运算符与equals()
查看>>
单工、半双工和全双工的定义
查看>>
Hdu【线段树】基础题.cpp
查看>>
时钟系统
查看>>
BiTree
查看>>
5个基于HTML5的加载动画推荐
查看>>
水平权限漏洞的修复方案
查看>>
静态链接与动态链接的区别
查看>>
Android 关于悬浮窗权限的问题
查看>>
如何使用mysql
查看>>
linux下wc命令详解
查看>>
敏捷开发中软件测试团队的职责和产出是什么?
查看>>
在mvc3中使用ffmpeg对上传视频进行截图和转换格式
查看>>
python的字符串内建函数
查看>>
Spring - DI
查看>>
微软自己的官网介绍 SSL 参数相关
查看>>
Composite UI Application Block (CAB) 概念和术语
查看>>