扫一遍整个串,每进来一个字符,往前扫(i = a to b)个字符,对每一个子字符串,最高位加上1后(防止忽略前导0)转为数字,对应次数加一。
主要是输出格式有点蛋疼,要仔细一点~
/*
PROG:contact
LANG:C++
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int a, b, n, cnt, tot, now, tmp;
char str[200001];
pair<int, int> hash[10001];
void convert(int num, char* ans)
{
while (num != 1)
{
ans[strlen(ans)] = '0' + (num & 1);
num >>= 1;
}
reverse(ans, ans+strlen(ans));
}
int main()
{
freopen("contact.in", "r", stdin);
freopen("contact.out", "w", stdout);
scanf("%d%d%d", &a, &b, &n);
for (int i = 0;i < 10001;++i) hash[i] = make_pair(0, i);
while (~scanf(" %c", &str[tot++]))
{
for (int i = a;i <= b;++i)
if (tot >= i)
{
now = 1;
for (int j = tot-i;j < tot;++j)
now = (now << 1) + str[j] - '0';
++hash[now].first;
}
}
sort(hash, hash+10001);
for (int j = 10000; ;j = tmp-1)
{
if (!hash[j].first) break;
printf("%d\n", hash[j].first);
tmp = j;
while (hash[tmp].first == hash[tmp-1].first) tmp--;
int count = 0;
for (int i = tmp; i <= j;++i)
{
++count;
char ans[15] = {'\0'};
convert(hash[i].second, ans);
printf("%s", ans);
if (count % 6 == 0 || i == j) printf("\n");
else printf(" ");
}
++cnt;
if (cnt == n) break;
}
}