若是凉夜已成梦

青春里 总有些事情要努力去做 总有些梦想要拼命去追。


  • 运维

  • 前端

  • 编程

  • 随笔

  • hust-oj

1118: Problem D – Zipf’s Law

发表于 2017-10-06   |   分类于 HUSTOJ   |   阅读次数 1,219

题目描述

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 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.

输出

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.

样例输入

2

In practice, the difference between theory and practice is always
greater than the difference between theory and practice in theory.
	- Anonymous

Man will occasionally stumble over the truth, but most of the
time he will pick himself up and continue on.
        - W. S. L. Churchill
EndOfText

样例输出

between
difference
in
will

参考代码

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int c,i,j,k,n,wn;
char w[10001][100], buf[1000];
int main() 
{
    while (1 == scanf("%d",&n)) 
    {
        if (c++) printf("n");
      wn = 0;
      for (;;) {
         if (1 != scanf("%[^a-zA-Z]",buf)) break;
         if (1 != scanf("%[a-zA-Z]",buf)) break;
         if (!strcmp(buf,"EndOfText")) break;
         for (i=0;buf[i];i++) buf[i] = tolower(buf[i]);
         strcpy(w[wn++],buf);
      }
      qsort(w,wn,100,strcmp);
      strcpy(w[wn++],"***");
      strcpy(buf,"$$$");
      for (i=j=0;i<wn;i++) {
         if (strcmp(buf,w[i])) {
            if (strcmp(buf,"$$$") && k == n) printf("%sn",buf),j=1;
            strcpy(buf,w[i]);
            k = 0;
         }
         k++;
      }
      if (!j) printf("There is no such word.n");
   }
}

解析

暂无

hustoj

发表评论 取消回复

邮箱地址不会被公开。 必填项已用*标注

*
*


hoxis wechat
著作权归作者所有
站点更新说明
  • 文章目录
  • 站点概览
若是凉夜已成梦

若是凉夜已成梦

青春里 总有些事情要努力去做 总有些梦想要拼命去追。

1904 日志
6 分类
12 标签
RSS
weibo github twitter facebook

友情链接

Skip 原站点 Dreams孤独患者
© 2017 若是凉夜已成梦
Powered by WordPress | 已运行
Theme By NexT.Mist