Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <string>
- #include <utility>
- void Shell(std::vector<std::pair<std::string, int>>& a, int n) {
- for (int step = n / 2; step > 0; step /= 2) {
- for (int i = step; i < n; ++i) {
- for (int j = i - step; j >= 0 && a[j].second > a[j + step].second; j -= step) {
- std::swap(a[j], a[j + step]);
- }
- }
- }
- return;
- }
- int main() {
- std::fstream str, ltr;
- std::ofstream rtr;
- str.open("f.txt");
- ltr.open("g.txt");
- rtr.open("r.txt");
- if (!str.is_open()) {
- std::cout << "FAILED TO OPEN FILE 1";
- return 0;
- }
- if (!ltr.is_open()) {
- std::cout << "FAILED TO OPEN FILE 2";
- return 0;
- }
- if (!rtr.is_open()) {
- std::cout << "FAILED TO OPEN FILE 3";
- return 0;
- }
- std::vector<std::pair<std::string, std::string>> a(1000);
- std::vector<std::vector<std::pair<std::string, int>>> b(100, std::vector<std::pair<std::string, int>>(100, std::make_pair<std::string, int>("", 0)));
- int i = 0;
- while (!str.eof()) {
- str >> a[i].first;
- str >> a[i].second;
- ++i;
- }
- int j = 0;
- while (!ltr.eof()) {
- std::string bin;
- ltr >> bin;
- char s;
- bool space = false, f = false;
- for (int j1 = -1; (s = ltr.get()) != '\n' && !ltr.eof();) {
- if (s == ' ') {
- space = !space;
- if (space) {
- ++j1;
- }
- continue;
- }
- if (space) {
- b[j][j1].first.push_back(s);
- f = false;
- }
- else {
- if (!f) {
- b[j][j1].second = s - '0';
- f = true;
- }
- else {
- b[j][j1].second *= 10;
- b[j][j1].second += s - '0';
- }
- }
- }
- ++j;
- }
- std::vector<std::pair<std::string, int>> fin(1000);
- std::vector<int> dub(1000, 0);
- for (int q = 0; q < i; ++q) {
- std::pair<int, int> mindub;
- mindub.first = 100000000;
- int fpos = 0;
- //bool leave;
- for (int q1 = 0; q1 < j; ++q1) {
- int pos = -1;
- for (int q2 = 0; q2 < b[q1].size(); ++q2) {
- if (b[q1][q2].first == "") {
- break;
- }
- if (b[q1][q2].first == a[q].second) {
- pos = q2;
- break;
- }
- }
- if (pos >= 0) {
- if (dub[q1] < mindub.first) {
- mindub.first = dub[q1];
- mindub.second = q1;
- fpos = pos;
- }
- }
- }
- if (mindub.first != 100000000) {
- fin[q].first = a[q].first;
- dub[mindub.second] += b[mindub.second][fpos].second;
- fin[q].second = dub[mindub.second];
- }
- else {
- fin[q].first = a[q].first;
- fin[q].second = -1;
- }
- }
- Shell(fin, i - 1);
- for (int w = 0; w < i - 1; ++w) {
- if (fin[w].second != -1) {
- rtr << fin[w].first << " " << 8 + fin[w].second / 60 << ':';
- if (fin[w].second % 60 < 10) {
- rtr << '0';
- rtr << fin[w].second % 60;
- }
- else {
- rtr << fin[w].second % 60;
- }
- rtr << "\n";
- }
- else {
- rtr << fin[w].first << " MUST BE ELIMINATED IMMEDIATLTY\n";
- }
- }
- str.close();
- ltr.close();
- rtr.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement