Zipf's Law(map容器)
来源:互联网 发布:内涵段子引流脚本源码 编辑:程序博客网 时间:2024/06/04 18:02
Zipf's Law
Time Limit: 3000MS Memory Limit: 65536KTotal Submissions: 1767 Accepted: 532
Description
Harvard linguistics professor George Kingsley Zipf (1902-1950) observed that the frequency of the kth most common word in a text is roughly proportional to 1/k. He justified his observations in a book titled Human behavior and the principle of least effort published in 1949. While Zipf's rationale has largely been discredited, the principle still holds, and others have afforded it a more sound mathematical basis.
You are to find all the words occurring n times in an English text. A word is a sequence of letters. Words are separated by non-letters. Capitalization should be ignored. A word can be of any length that an English word can be.
You are to find all the words occurring n times in an English text. A word is a sequence of letters. Words are separated by non-letters. Capitalization should be ignored. A word can be of any length that an English word can be.
Input
Input consists of several test cases. The first line of each case contains a single positive integer n. Several lines of text follow which will contain no more than 10000 words. The text for each case is terminated by a single line containing EndOfText. EndOfText does not appear elsewhere in the input and is not considered a word.
Output
For each test case, output the words which occur n times in the input text, one word per line, lower case, in alphabetical order. If there are no such words in input, output the following line:
There is no such word.
Leave a blank line between cases.
There is no such word.
Leave a blank line between cases.
Sample Input
2In practice, the difference between theory and practice is alwaysgreater than the difference between theory and practice in theory.- AnonymousMan will occasionally stumble over the truth, but most of thetime he will pick himself up and continue on. - W. S. L. ChurchillEndOfText
Sample Output
betweendifferenceinwill
Source
Waterloo local 2001.06.02
map容器,很轻松啊!
#include<cstdio>#include<iostream>#include<string>#include<sstream>#include<cstring>#include<map>using namespace std;int main(){ string s,buf; int i,f,n,num=0; while(cin>>n) { f=0; map<string,int>mp; while (cin>>s&&s!="EndOfText") { for(i=0;i<s.length();i++) { if (isalpha(s[i])) { s[i]=tolower(s[i]); } else { s[i]=' '; } } stringstream ss(s); while (ss>>buf) { mp[buf]++; } } if(num!=0) { cout<<endl; } for(map<string,int>::iterator it=mp.begin();it!=mp.end();it++) { if(it->second==n) { cout<<it->first<<endl; f=1; } } if(f==0) { cout<<"There is no such word."<<endl; } num++; }}
0 0
- Zipf's Law(map容器)
- Zipf's law分析
- Zipf's law
- ZCMU-Problem D - Zipf's Law
- poj2550&&zcmu1867——Zipf's Law
- 胡克定律(Hooke's law)
- 语言统计学三大定律:Zipf law,Heaps law和Benford law
- 摩菲定理(Murphy's Law)
- Amdahl's law(阿姆达尔定律)
- 墨菲定律(Murphy's Law)
- 墨菲定律(Murphy's law)
- 利特尔定理(Little’s Law)
- 阿姆达尔定律(Amdahl's law)
- Moore's law & Hook's law
- Amdahl's Law
- Murphy's Law
- Amdahl's law
- MOORE'S LAW
- LRU(Least Recently Used)最近最少使用页面置换算法
- 网络文件传输
- error inflating class com.baidu.mapapi.map.mapview
- STL Application 1
- 获取android已安装的应用PackageInfo启动第三方APP应用
- Zipf's Law(map容器)
- 状态模式
- B\S备忘录21——使用反射将委托挂钩
- SSO 之CAS单点登录笔记
- 编译低版本Gcc (<gcc3.4.6),报错error: unrecognizable insn:
- 编程之路从大学毕业开启
- 简单搜索框的制作
- Python连接mysql数据库
- C++程序运行时间优化