1071. Speech Patterns
来源:互联网 发布:女装淘宝首页 编辑:程序博客网 时间:2024/06/05 11:29
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 <stdio.h>#include <stdlib.h>#include <iostream>#include <string>#include <map>using namespace std;#define N 1048580bool Check (char a);int main (){ string str; getline(cin,str); int len=str.length(),i=0; map<string,int> mp; while( i<len) { string temp; while( i<len && Check(str[i])) { if( str[i]-'A'>=0&&str[i]-'Z'<=0) str[i]+=32; temp+=str[i]; i++; } if( temp!="") { if( mp.find(temp)==mp.end()) mp[temp]=1; else mp[temp]++; } while( i<len&&Check(str[i])==false) i++; } string ans; int max=0; for( map<string,int>::iterator it=mp.begin();it!=mp.end();it++) { if( it->second>max) { max=it->second; ans=it->first; } } printf("%s %d\n",ans,max); system("pause"); return 0; }bool Check (char a){ if( a>='0'&&a<='9') return true; if( a>='a'&&a<='z') return true; if( a>='A'&&a<='Z') return true; return false; }
- 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
- 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)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 准备篇:系统环境设置
- Yii2 缓存
- Android项目学习—Intent的作用详解
- 利用C#的反射机制动态调用DLL类库
- 数据结构之二叉树(遍历、建立、深度)
- 1071. Speech Patterns
- 两会背景下的主题投资基金
- find和find_if
- Machine Learning SVM
- 5.PMAC下位机-下位机编程基础
- 【Android】【Activity】Activity的4种加载模式及Intent标识
- 【ACM之旅】拼写检查
- BZOJ 3903 比赛 最小割
- YT15-HDU-字符串的模拟