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

首頁 > 學院 > 開發設計 > 正文

ZCMU-Problem D - Zipf's Law

2019-11-11 04:56:28
字體:
來源:轉載
供稿:網友

PRoblem D: Problem D - ZTime Limit: 1 Sec  Memory Limit: 128 MBSubmit: 22  Solved: 5[Submit][Status][Web Board]

Description

Problem D - Zipf's Law

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.

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【解析】這道題就是輸入一個n和一段文本,在輸入到EndOfText表示此段文本輸入結束,然后判斷輸入的這段文本當中有哪些單詞出現了兩次。所以我們其實可以用map<string,int>來做,進行統計就好了,而且這個就是按照字典序來排序下去的。所以我們統計完直接遍歷就可以了,這里需要擁有stringsteam來進行拆解除每一個單詞。
#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<map>#include<sstream>#include<algorithm>using namespace std;map<string,int>a;int main(){    int n,flag=0,i,flag1;    string s;    while(~scanf("%d",&n))    {        a.clear();        if(flag==0)        {            flag=1;//在第2次以及以后的輸入n之后都要先輸出一個空行        }        else if(flag==1)        {            printf("/n");        }        while(getline(cin,s))//逐行讀取        {            if(s=="EndOfText")                break;            else            {                for(i=0;i<s.size();i++)                {                    if(isalpha(s[i]))                        s[i]=tolower(s[i]);                    else                        s[i]=' ';/*這里一定要注意不是字母的就一定要變成空格                        不然其他字符出現了n次也會輸出*/                }            }            stringstream s1(s);            string s2;            while(s1>>s2)//以空格為邊界            {                a[s2]++;            }        }        flag1=0;//標記有沒有出現過n次的單詞        for(map<string,int>::iterator it=a.begin();it!=a.end();it++)        {            if(it->second==n)            {                flag1=1;                cout<<it->first<<endl;            }        }        if(flag1==0)            printf("There is no such word./n");//表示沒有這樣的單詞    }    return 0;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 苏尼特左旗| 凉山| 东阳市| 崇阳县| 鄄城县| 石林| 元阳县| 旬阳县| 鄱阳县| 台东县| 南澳县| 如皋市| 郁南县| 华蓥市| 仪陇县| 夏邑县| 温州市| 永嘉县| 共和县| 托克逊县| 荥阳市| 宁武县| 鸡东县| 安塞县| 清河县| 会东县| 海原县| 迭部县| 仙桃市| 洪湖市| 西峡县| 栖霞市| 莲花县| 庆元县| 遂川县| 南昌县| 泰宁县| 礼泉县| 新巴尔虎右旗| 衡阳县| 晴隆县|