Advertisement
LegoSosiska

Untitled

Nov 25th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <string>
  5. #include <utility>
  6.  
  7. void Shell(std::vector<std::pair<std::string, int>>& a, int n) {
  8.     for (int step = n / 2; step > 0; step /= 2) {
  9.         for (int i = step; i < n; ++i) {
  10.             for (int j = i - step; j >= 0 && a[j].second > a[j + step].second; j -= step) {
  11.                 std::swap(a[j], a[j + step]);
  12.             }
  13.         }
  14.     }
  15.     return;
  16. }
  17.  
  18. int main() {
  19.     std::fstream str, ltr;
  20.     std::ofstream rtr;
  21.     str.open("f.txt");
  22.     ltr.open("g.txt");
  23.     rtr.open("r.txt");
  24.     if (!str.is_open()) {
  25.         std::cout << "FAILED TO OPEN FILE 1";
  26.         return 0;
  27.     }
  28.     if (!ltr.is_open()) {
  29.         std::cout << "FAILED TO OPEN FILE 2";
  30.         return 0;
  31.     }
  32.     if (!rtr.is_open()) {
  33.         std::cout << "FAILED TO OPEN FILE 3";
  34.         return 0;
  35.     }
  36.     std::vector<std::pair<std::string, std::string>> a(1000);
  37.     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)));
  38.     int i = 0;
  39.     while (!str.eof()) {
  40.         str >> a[i].first;
  41.         str >> a[i].second;
  42.         ++i;
  43.     }
  44.     int j = 0;
  45.     while (!ltr.eof()) {
  46.         std::string bin;
  47.         ltr >> bin;
  48.         char s;
  49.         bool space = false, f = false;
  50.         for (int j1 = -1; (s = ltr.get()) != '\n' && !ltr.eof();) {
  51.             if (s == ' ') {
  52.                 space = !space;
  53.                 if (space) {
  54.                     ++j1;
  55.                 }
  56.                 continue;
  57.             }
  58.             if (space) {
  59.                 b[j][j1].first.push_back(s);
  60.                 f = false;
  61.             }
  62.             else {
  63.                 if (!f) {
  64.                     b[j][j1].second = s - '0';
  65.                     f = true;
  66.                 }
  67.                 else {
  68.                     b[j][j1].second *= 10;
  69.                     b[j][j1].second += s - '0';
  70.                 }
  71.             }
  72.         }
  73.         ++j;
  74.     }
  75.     std::vector<std::pair<std::string, int>> fin(1000);
  76.     std::vector<int> dub(1000, 0);
  77.     for (int q = 0; q < i; ++q) {
  78.         std::pair<int, int> mindub;
  79.         mindub.first = 100000000;
  80.         int fpos = 0;
  81.         //bool leave;
  82.         for (int q1 = 0; q1 < j; ++q1) {
  83.             int pos = -1;
  84.             for (int q2 = 0; q2 < b[q1].size(); ++q2) {
  85.                 if (b[q1][q2].first == "") {
  86.                     break;
  87.                 }
  88.                 if (b[q1][q2].first == a[q].second) {
  89.                     pos = q2;
  90.                     break;
  91.                 }
  92.             }
  93.             if (pos >= 0) {
  94.                 if (dub[q1] < mindub.first) {
  95.                     mindub.first = dub[q1];
  96.                     mindub.second = q1;
  97.                     fpos = pos;
  98.                 }
  99.             }
  100.         }
  101.         if (mindub.first != 100000000) {
  102.             fin[q].first = a[q].first;
  103.             dub[mindub.second] += b[mindub.second][fpos].second;
  104.             fin[q].second = dub[mindub.second];
  105.         }
  106.         else {
  107.             fin[q].first = a[q].first;
  108.             fin[q].second = -1;
  109.         }
  110.     }
  111.     Shell(fin, i - 1);
  112.     for (int w = 0; w < i - 1; ++w) {
  113.         if (fin[w].second != -1) {
  114.             rtr << fin[w].first << " " << 8 + fin[w].second / 60 << ':';
  115.             if (fin[w].second % 60 < 10) {
  116.                 rtr << '0';
  117.                 rtr << fin[w].second % 60;
  118.             }
  119.             else {
  120.                 rtr << fin[w].second % 60;
  121.             }
  122.             rtr << "\n";
  123.         }
  124.         else {
  125.             rtr << fin[w].first << " MUST BE ELIMINATED IMMEDIATLTY\n";
  126.         }
  127.     }
  128.     str.close();
  129.     ltr.close();
  130.     rtr.close();
  131. }
  132.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement