国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設計 > 正文

poj2550&&zcmu1867——Zipf's Law

2019-11-11 02:50:19
字體:
供稿:網(wǎng)友

                                                              Z
Time Limit: 3000MS Memory Limit: 65536K
Total Submissions: 1812 Accepted: 546

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.

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.

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

題目大意:給你一個文本,讓你找出出現(xiàn)次數(shù)為n的字符串,每個測試數(shù)據(jù)之間輸出一個空行,跟描述基本沒有什么關系再見

#include <cstdio>#include <iostream>#include <cstring>#include <sstream>#include <map>using namespace std;map<string,int>a;int main(){    string s,buf;    int n,flag=0;    while (~scanf("%d",&n))    {        if (flag)            puts("");        flag++;        a.clear();        while (getline(cin,s)&&s!="EndOfText")        {            for(int i=0; i<s.length(); i++)                if (isalpha(s[i]))                    s[i]=tolower(s[i]);                else                    s[i]=' ';            stringstream ss(s);//定義了一個字符串流,并用一個字符串初始化            while (ss>>buf)//將字符串流中的字符串一個個的輸出到buf中            {                a[buf]++;                //cout<<buf<<endl;            }        }        int tt=0;        map<string,int>::iterator it;        for(it=a.begin(); it!=a.end(); it++)            if(it->second==n)            {                tt=1;                cout<<it->first<<endl;            }        if(!tt) printf("There is no such word./n");    }}


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 拜城县| 颍上县| 台江县| 博罗县| 金昌市| 田阳县| 增城市| 秦安县| 西乌珠穆沁旗| 凤台县| 于都县| 江西省| 龙里县| 宁南县| 大冶市| 土默特右旗| 肃北| 常宁市| 遂昌县| 玛多县| 榆林市| 泌阳县| 永昌县| 兴和县| 安陆市| 郑州市| 周至县| 乌拉特中旗| 峨边| 青海省| 西盟| 宁蒗| 泽普县| 鄂州市| 鹰潭市| 桃园市| 邳州市| 昆山市| 安图县| 原阳县| 通江县|