"POJ11855" buzzwords (suffix array)

Source: Internet
Author: User

Description

The word "the" is the most common
Three-letter Word. It even
Shows up inside other words, such
As "other" and "mathematics".
Sometimes it hides, split between
Words, such as "not here."
Have your ever wondered what the
Most common words of lengths
Other than three is?
Your task is the following. You
would be given a text. In the This text,
Find the most common word of
Length one. If there is multiple
Such words, any one would do. Then
Count how many times the most
Common Word appears in the text. If It appears more than once, the output how many times it appears.
Then repeat the process with words of length 2, 3, and so on, until your reach such a length that
There is no longer any repeated word of that, length in the text.

Input

The input consists of a sequence of lines. The last line of input was empty and should not being processed.

Each line of input and than the last contains at least one and no more than one thousand uppercase
Letters and spaces. The spaces is irrelevant and should be ignored.

Output
For each line of input, output a sequence of lines, giving the number of repetitions of words of length
1, 2, 3, and so on. When your reach a length such that there is no repeated words of that length,
Output one blank line, does not output anything further for that input line, and move over to the next line
of input.
Note:remember the last line of the sample input and of the sample output must is blank.


Sample Input
The other mathematics isn't here
Aa


Sample Output
5
4
4
2
2
2

Test instructions

Given a text, find the length of 1, 2, 3, 4, 5 .... The maximum number of occurrences of a string, and the number of occurrences is not greater than 1.

Analysis

Direct for two times. Group by the length of the enumeration to find Max for the number of members of the group.

The code is as follows:

1#include <cstdio>2#include <cstdlib>3#include <cstring>4#include <iostream>5#include <algorithm>6#include <queue>7 using namespacestd;8 #defineMaxl 1000109 #defineINF 0XFFFFFFFTen  One intL,len; A CharS[MAXL]; - intc[maxl],cl; -  the intMymin (intXintY) {returnX<y?x:y;} - intMymax (intXintY) {returnX>y?x:y;} -  - voidInit () + { -len=strlen (s); +Cl=0; A      for(intI=0; i<len;i++)if(s[i]!=' ') atc[++cl]=s[i]-'A'+1; - } -  - intSA[MAXL],RK[MAXL],Y[MAXL],WR[MAXL],RS[MAXL]; - voidGet_sa (intm) - { inmemcpy (Rk,c,sizeof(RK)); -      for(intI=0; i<=m;i++) rs[i]=0; to      for(intI=1; i<=cl;i++) rs[rk[i]]++; +      for(intI=1; i<=m;i++) rs[i]+=rs[i-1]; -      for(inti=cl;i>=1; i--) sa[rs[rk[i]]--]=i; the      *     intln=1, p=0; $      while(p<cl)Panax Notoginseng     { -         intk=0; the          for(inti=cl-ln+1; i<=cl;i++) y[++k]=i; +          for(intI=1; i<=cl;i++)if(SA[I]&GT;LN) y[++k]=sa[i]-Ln; A          for(intI=1; i<=cl;i++) wr[i]=Rk[y[i]]; the          +          for(intI=0; i<=m;i++) rs[i]=0; -          for(intI=1; i<=cl;i++) rs[wr[i]]++; $          for(intI=1; i<=m;i++) rs[i]+=rs[i-1]; $          for(inti=cl;i>=1; i--) sa[rs[wr[i]]--]=Y[i]; -          -          for(intI=1; i<=cl;i++) wr[i]=Rk[i]; the          for(inti=cl+1; i<=cl+ln;i++) wr[i]=0; -p=1, rk[sa[1]]=1;Wuyi          for(intI=2; i<=cl;i++) the         { -             if(wr[sa[i]]!=wr[sa[i-1]]|| wr[sa[i]+ln]!=wr[sa[i-1]+LN]) p++; Wurk[sa[i]]=p; -         } Aboutln*=2, m=p; $     } -sa[0]=rk[0]=0; - } -  A intHEIGHT[MAXL]; + voidget_he () the { -     intk=0; $      for(intI=1; i<=cl;i++)if(rk[i]!=1) the     { the         intj=sa[rk[i]-1]; the         if(k) k--; the          while(C[I+K]==C[J+K]&AMP;&AMP;I+K&LT;=CL&AMP;&AMP;J+K&LT;=CL) k++; -height[rk[i]]=K; in     } the } the  About voidFfind () the { the      for(intI=1; i<=cl;i++)//Enumeration Length I the     { +         intCnt=0, ans=0; -          for(intj=1; j<=cl;j++) the         {Bayicnt++; the             if(height[j+1]<i| | J==CL)//is the end of a group the             { -                 if(cnt!=1) ans=Mymax (ans,cnt); -Cnt=0; the             } the         } the         if(ans<=1) Break; theprintf"%d\n", ans); -     } the } the  the intMain ()94 { the     BOOLok=0; the      while(gets (s)) the     {98         if(OK) printf ("\ n"); Aboutok=1; - init ();101Get_sa ( -);102 get_he ();103 Ffind ();104     } the     return 0;106}
[UVA11855]

2016-07-19 16:31:07

"POJ11855" buzzwords (suffix array)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.