显示代码纯文本
/*
ID:zyfwork1
LANG:C++
TASK:contact
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#define loop(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const char base='0';
const int sonnum=2;
class Trie{public:bool isStr;class Trie *son[sonnum]; int pos;};
class mystring{public:int times;char s[13];}S[100000];
int A,B,N,M,top=0;
char str[200010];
Trie *Root;
Trie *NewTrie()
{
Trie *temp=new Trie; loop(i,0,sonnum-1) temp->son[i]=NULL;
temp->isStr=false,temp->pos=0; return temp;
}
void Find(Trie *pnt,int start,int len)
{
Trie *temp=pnt; loop(i,start,start+len-1)
{
if(temp->son[str[i]-base]==NULL)
temp->son[str[i]-base]=NewTrie();
temp=temp->son[str[i]-base];
}
if(!temp->isStr)
{
temp->isStr=true; M++; temp->pos=M;
S[M].times=1; memset(S[M].s,'\0',sizeof(S[M].s));
loop(i,start,start+len-1) S[M].s[i-start]=str[i]; return;
}
S[temp->pos].times++;
}
inline bool cmp(const mystring& a,const mystring& b)
{
if(a.times!=b.times) return a.times>b.times;
int al=strlen(a.s),bl=strlen(b.s);
if(al!=bl) return al<bl;
if(strcmp(a.s,b.s)>0) return 0;
return 1;
}
void init()
{
scanf("%d %d %d\n",&A,&B,&N);Root=NewTrie();
char c; while(scanf("%c",&c)!=EOF) {if(c=='0' || c=='1') str[top++]=c;}
for(int i=A;i<=B;i++)
for(int len=0;len+i<=(int)strlen(str);len++)
Find(Root,len,i);
}
void solve()
{
sort(S+1,S+M+1,cmp);
int p=1,n=0,now=-1994,pos=0;
while(p<=M)
{
if(S[p].times!=now)
{
if(n==N) break;
if(n!=0) printf("\n"); n++;
pos=0; printf("%d\n%s",S[p].times,S[p].s);
now=S[p].times; p++; continue;
}
pos++; if(!(pos%6)) printf("\n%s",S[p].s);
else printf(" %s",S[p].s);
p++;
}
printf("\n");
}
int main()
{
freopen("contact.in","r",stdin);
freopen("contact.out","w",stdout);
init();
solve();
return 0;
}