Advertisement
martukha

1

Apr 24th, 2020
687
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.22 KB | None | 0 0
  1. #include<iostream>
  2. #include<algorithm>
  3. #include<string>
  4. #include<vector>
  5. #include<fstream>
  6. #include<map>
  7.  
  8. using namespace std;
  9.  
  10. class Event {
  11. public:
  12.     string data,name,category,place,visitor,vis;
  13.     Event():data(" "),name(" "), category(" "),place(" "),visitor(" "),vis(" "){}
  14.     Event(string d, string n,string c, string p,string v,string v1):data(d),name(n),category(c),place(p),visitor(v),vis(v1){}
  15.     Event(const Event& e) : data(e.data), name(e.name), category(e.category), place(e.place),visitor(e.visitor),vis(e.vis){}
  16.  
  17.    
  18.  
  19.     friend istream& operator>>(istream& in, Event& e) {
  20.         in >> e.data;
  21.         in >> e.name;
  22.         in >> e.category;
  23.         in >> e.place;
  24.         in >> e.visitor;
  25.         in >> e.vis;
  26.         return in;
  27.     }
  28. };
  29.  
  30. int main() {
  31.     ifstream in("Text.txt");
  32.     vector<Event> ev;
  33.     size_t size = 6;
  34.     for (size_t i = 0; i < size; i++)
  35.     {
  36.         Event events;
  37.         in >> events;
  38.         ev.push_back(events);
  39.     }
  40.    
  41.     sort(ev.begin(), ev.end(), [](const Event& e1, const Event& e2)
  42.         {
  43.             return e1.data < e2.data && e1.name<e2.name &&e1.category<e2.category;
  44.         });
  45.    
  46.     ofstream file("out.dat");
  47.     file << "1." << endl;
  48.     for (auto it: ev)
  49.     {
  50.         file << "Data:" << it.data<< "\tName:" << it.name << "\tCategory:" << it.category << "\tPlace:" << it.place<<"\tVisitors:"<<it.visitor <<","<<it.vis<< endl;
  51.     }
  52.     //__________________________//
  53.  
  54.    
  55.     sort(ev.begin(), ev.end(), [](const Event& e1, const Event& e2)
  56.         {
  57.             return e1.category < e2.category;
  58.         });
  59.  
  60.     ofstream fille("ou.dat");
  61.     fille << "2." << endl;
  62.     for (auto item:ev)
  63.     {
  64.         fille << "\tCategory:" << item.category << "\tName:" << item.name << "\tData:" << item.data << endl;
  65.     }
  66.     //__________________________//
  67.  
  68.  
  69.     int num_1 = count_if(ev.begin(), ev.end(), [](const Event&e)
  70.         {
  71.             return e.visitor == "Chorna"|| e.vis=="Chorna";
  72.         }
  73.     );
  74.     int num_2 = count_if(ev.begin(), ev.end(), [](const Event& e)
  75.         {
  76.             return e.visitor == "Bila"|| e.vis=="Bila";
  77.         });
  78.     int num_3 = count_if(ev.begin(), ev.end(), [](const Event& e)
  79.         {
  80.             return e.visitor == "Synya"|| e.vis=="Synya";
  81.         });
  82.  
  83.     ofstream text("o.dat");
  84.     text << "3." << endl;
  85.     text << "Chorna-" << num_1 << endl;
  86.     text << "Bila-" << num_2 << endl;
  87.     text << "Synya-" << num_3 << endl;
  88.    
  89.    
  90.     system("pause");
  91.     return 0;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement