Skip to content

Instantly share code, notes, and snippets.

@zao
Created July 1, 2017 23:31
Show Gist options
  • Save zao/0d5ae29c00f776f0ea72e785b8f55428 to your computer and use it in GitHub Desktop.
Save zao/0d5ae29c00f776f0ea72e785b8f55428 to your computer and use it in GitHub Desktop.
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <vector>
int main(int argc, char* argv[]) {
std::string line;
std::vector<std::string> prelude, postlude;
std::map<int, std::vector<std::string>> groups;
while (std::getline(std::cin, line)) {
int proj_idx;
if (1 == sscanf(line.c_str(), "%d>", &proj_idx)) {
groups[proj_idx].push_back(line);
}
else {
if (groups.empty()) {
prelude.push_back(line);
}
else {
postlude.push_back(line);
}
}
}
for (auto const& line : prelude) {
std::cout << line << std::endl;
}
for (auto const& g : groups) {
for (auto const& line : g.second) {
std::cout << line << std::endl;
}
}
for (auto const& line : postlude) {
std::cout << line << std::endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment