Advertisement
ostapdontstop

dates

Feb 18th, 2019
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.96 KB | None | 0 0
  1. #include <fstream>
  2. #include <vector>
  3. #include <map>
  4. #include <string>
  5. #include <algorithm>
  6. using namespace std;
  7.  
  8. struct date {
  9.     int day, duration, k;
  10.     int begTime, endTime;
  11.     char time[6];
  12.     vector <string> names;
  13. };
  14.  
  15. bool TimeOrder(const date *a, const date *b) {
  16.     return a->day < b->day || a->begTime < b->begTime;
  17. }
  18.  
  19. int main(int argc, char const *argv[])
  20. {  
  21.     ifstream fin("input.txt");
  22.     ofstream fout("output.txt");
  23.  
  24.     string buff;
  25.     // vector <date*> dates;
  26.     map <string, vector<date*>> name_dates;
  27.  
  28.     int print_day;
  29.     string print_name;
  30.  
  31.     bool fail;
  32.  
  33.     int n; fin >> n;
  34.  
  35.     for (int ii = 0; ii < n; ++ii)
  36.     {
  37.         fin >> buff;
  38.         if (buff == "APPOINT")
  39.         {  
  40.             date* x = new date();
  41.             fin >> x->day >> x->time >> x->duration >> x->k;
  42.             x->begTime = atoi(x->time) * 60;
  43.             x->begTime+= atoi(x->time+3);
  44.             x->endTime = x->begTime + x->duration;
  45.  
  46.             fail = 0;
  47.             for (int ki = 0; ki < x->k; ++ki)
  48.             {
  49.                 fin >> buff;
  50.                 x->names.push_back(buff);
  51.  
  52.                 for (auto i = name_dates[buff].begin();
  53.                     i != name_dates[buff].end(); ++i) {
  54.                         if (x->day == (*i)->day &&
  55.                             x->begTime < (*i)->endTime &&
  56.                             x->endTime > (*i)->begTime) {
  57.                                 if (!fail) {
  58.                                     fail = 1;
  59.                                     fout << "FAIL\n";
  60.                                 }
  61.                                 fout << buff << ' ';
  62.                         }
  63.                 }
  64.             }
  65.  
  66.  
  67.             if (!fail) {
  68.                 // dates.push_back(x);
  69.                 fout << "OK";
  70.  
  71.                 for (auto j = x->names.begin(); j != x->names.end(); ++j) {
  72.                     name_dates[*j].push_back(x);
  73.                     sort(name_dates[*j].begin(), name_dates[*j].end(), TimeOrder);
  74.                 }
  75.             }
  76.             fout << '\n';
  77.         }
  78.         else if (buff == "PRINT") {
  79.             fin >> print_day >> print_name;
  80.             for (auto i = name_dates[print_name].begin();
  81.                 i != name_dates[print_name].end(); ++i)
  82.             {
  83.                 if (print_day == (*i)->day)
  84.                 {
  85.                     fout << (*i)->time << ' ' << (*i)->duration;
  86.                     for (auto j = (*i)->names.begin(); j != (*i)->names.end(); ++j)
  87.                         fout << ' ' << *j;
  88.                     fout << '\n';
  89.  
  90.                 }
  91.             }
  92.         }
  93.     }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement