-
Notifications
You must be signed in to change notification settings - Fork 0
/
contact.cpp
93 lines (93 loc) · 1.99 KB
/
contact.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
ID: wanggen3
PROG: contact
LANG: C++
*/
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
class element
{
public:
int content;
int count;
string cnt;
element():count(0){
}
};
ifstream fin("contact.in");
ofstream fout("contact.out");
bool cmp(const element& e1, const element& e2)
{
return (e1.count > e2.count)
||(e1.count == e2.count && e1.content < e2.content);
}
string toStr(int val)
{
string s;
while(val > 1)
{
s = (char)('0'+(val%2))+s;
val /= 2;
}
return s;
}
int main(int argv,char*argc[])
{
int A,B,N;
fin >> A >> B >> N;
string content;
string temp;
vector<element> counter(1<<13);
for(int i=0;i< (1<<13); ++i) counter[i].content = i;
while(fin >> temp) content += temp;
for(int i=A; i <=B;++i)
{
for(int j=0; j <= (int)content.size()-i; ++j)
{
int value=1;
for(int k=0; k < i; ++k)
{
value = value*2 + (content[j+k]-'0');
}
counter[value].count++;
}
}
sort(counter.begin(),counter.end(),cmp);
int outputCount=0;
int preCount = 0;
int i=0;
int lineCounter;
while(i < counter.size() && outputCount <= N)
{
if(counter[i].count==preCount)
{
if(lineCounter%6==0)
fout <<endl<< toStr(counter[i].content);
else
fout <<" "<< toStr(counter[i].content);
lineCounter++;
}
else
{
outputCount++;
lineCounter=1;
if(outputCount > N || counter[i].count==0)break;
preCount = counter[i].count;
if(outputCount>1)
{
fout << endl;
}
fout << counter[i].count << endl;
fout << toStr(counter[i].content);
}
i++;
}
fout << endl;
fin.close();
fout.close();
return 0;
}