Created
December 18, 2014 13:59
-
-
Save cengiz-io/9407ffefbeb8fd514d70 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <sstream> | |
#include <fstream> | |
#include <queue> | |
using namespace std; | |
struct OrderByLength { | |
bool operator() (string const &a, string const &b) { | |
return a.length() < b.length(); | |
} | |
}; | |
int main(int argc, char *argv[]) { | |
if (argc < 2) return -1; | |
ifstream datafile(argv[1]); | |
priority_queue<string, vector<string>, OrderByLength> lines; | |
string line; | |
int count = 0; | |
while (getline(datafile, line)) { | |
if (line.length() < 1) | |
continue; | |
if (count == 0) { | |
istringstream splitter(line); | |
splitter >> count; | |
continue; | |
} | |
lines.push(line); | |
} | |
for (int x = 0; x < count; x++) { | |
cout << lines.top() << endl; | |
lines.pop(); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment