blob: 45873a4ac7ef0a57b1276a3800b36c06eccad8d8 (
plain)
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
|
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <cassert>
#include "pruneGeneration.h"
using namespace std;
int main(int argc, char **argv)
{
cerr << "Starting" << endl;
int limit = atoi(argv[1]);
vector<Rec> records;
string prevInWord;
string line;
while (getline(cin, line)) {
vector<string> toks;
Tokenize(toks, line);
assert(toks.size() == 4);
if (prevInWord != toks[0]) {
Output(limit, records);
records.clear();
}
// add new record
float prob = atof(toks[2].c_str());
records.push_back(Rec(prob, line));
prevInWord = toks[0];
}
// last
Output(limit, records);
records.clear();
cerr << "Finished" << endl;
}
void Output(int limit, vector<Rec> &records)
{
Prune(limit, records);
for (size_t i = 0; i < limit && i < records.size(); ++i) {
const Rec &rec = records[i];
cout << rec.line << endl;
}
}
void Prune(int limit, std::vector<Rec> &records)
{
std::sort(records.rbegin(), records.rend());
}
|