Advertisement
adwas33

Untitled

Jan 21st, 2022
1,011
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.  
  9.     int liczbaLudzi;
  10.     cin>>liczbaLudzi;
  11.     vector<int> ludzie;
  12.     for(int i=0;i<liczbaLudzi;i++)
  13.     {
  14.         int val;
  15.         cin>>val;
  16.         ludzie.push_back(val);
  17.     }
  18.     sort(ludzie.begin(),ludzie.end());
  19.     int ileRazyTrzebaZrobicAlgorytmy=0;
  20.     while(!ludzie.empty())
  21.     {
  22.         while(ludzie[0]!=ludzie[1])
  23.         {
  24.             if(ludzie[0]<ludzie[1])
  25.             {
  26.                 ludzie[0]++;
  27.                 ileRazyTrzebaZrobicAlgorytmy++;
  28.             }
  29.             if(ludzie[0]>ludzie[1])
  30.             {
  31.                 ludzie[1]++;
  32.                 ileRazyTrzebaZrobicAlgorytmy++;
  33.             }
  34.         }
  35.         if(ludzie[0]==ludzie[1])
  36.         {
  37.             ludzie.erase(ludzie.begin());
  38.             ludzie.erase(ludzie.begin());
  39.         }
  40.     }
  41.  
  42.     cout<<"Trzeba zrobic "<<ileRazyTrzebaZrobicAlgorytmy<<" algorytmow ";
  43.     std::cout << "Hello, World!" << std::endl;
  44.     return 0;
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement