麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

ZCMU-Problem D - Zipf's Law

2019-11-11 04:59:33
字體:
供稿:網(wǎng)友

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【解析】這道題就是輸入一個(gè)n和一段文本,在輸入到EndOfText表示此段文本輸入結(jié)束,然后判斷輸入的這段文本當(dāng)中有哪些單詞出現(xiàn)了兩次。所以我們其實(shí)可以用map<string,int>來做,進(jìn)行統(tǒng)計(jì)就好了,而且這個(gè)就是按照字典序來排序下去的。所以我們統(tǒng)計(jì)完直接遍歷就可以了,這里需要擁有stringsteam來進(jìn)行拆解除每一個(gè)單詞。
#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之后都要先輸出一個(gè)空行        }        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]=' ';/*這里一定要注意不是字母的就一定要變成空格                        不然其他字符出現(xiàn)了n次也會(huì)輸出*/                }            }            stringstream s1(s);            string s2;            while(s1>>s2)//以空格為邊界            {                a[s2]++;            }        }        flag1=0;//標(biāo)記有沒有出現(xiàn)過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;}
上一篇:PAT BASIC 1004

下一篇:共享文件問題

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 亚洲成人精品久久久 | 主人在调教室性调教女仆游戏 | 日韩一级毛毛片 | 一级性色 | 国产精品亚洲精品久久 | 粉嫩粉嫩一区二区三区在线播放 | 久久久久一区二区三区 | 成人毛片视频在线观看 | 91九色论坛 | 全视频tv | chinese军人gay呻吟 | 国产精品免费久久久久 | 国产欧美在线观看不卡一 | 中文字幕欧美亚洲 | 素人视频免费观看 | 国产做爰 | 国产午夜精品久久久久婷 | 国产九九在线视频 | 国产精品三级a三级三级午夜 | 国产女厕一区二区三区在线视 | 亚洲一区二区三区在线免费观看 | 青久草视频 | 精品久久久久久久久久久αⅴ | 欧美日韩中文字幕在线视频 | 午夜久久久精品一区二区三区 | 亚洲精品a级 | 免费毛片视频 | 一本一道久久久a久久久精品91 | 午夜国内精品a一区二区桃色 | 成人毛片免费在线 | 三级xxxx| 91网视频 | 日本网站在线播放 | 一区二区免费网站 | 国产91丝袜在线熟 | 羞羞的视频在线 | 免费久久精品 | 一级性生活免费视频 | 操操影视 | 毛片一区二区三区四区 | 成人福利在线免费观看 |