Advertisement
MeehoweCK

Untitled

Oct 19th, 2020
2,276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1. // wersja ostateczna
  2. #include <iostream>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. unsigned kto_na_prawo(unsigned nr_osoby, unsigned* osoby)
  8. {
  9.     return osoby[nr_osoby - 1];
  10. }
  11.  
  12. unsigned znajdz_pierwsza(unsigned* osoby)
  13. {
  14.     for(int i = 0; true; ++i)
  15.         if(osoby[i] != 0)
  16.             return i + 1;
  17. }
  18.  
  19. int main()
  20. {
  21.     unsigned n;
  22.     cin >> n;
  23.  
  24.     // 1.
  25.     unsigned osoby[n];
  26.     for(unsigned i = 0; i < n; ++i)
  27.         cin >> osoby[i];
  28.  
  29.     // 2.
  30.     vector<unsigned> stol;
  31.  
  32.     unsigned usadzeni = 0, x, liczba_osob, stoly = 0;
  33.     // 3.
  34.     while(usadzeni < n)
  35.     {
  36.         stol.clear();
  37.         stol.push_back(znajdz_pierwsza(osoby));
  38.  
  39.         x = kto_na_prawo(stol[0], osoby);
  40.  
  41.         while(x != stol[0])
  42.         {
  43.             stol.push_back(x);
  44.             x = kto_na_prawo(stol[stol.size() - 1], osoby);
  45.         }
  46.  
  47.         // 4.
  48.         liczba_osob = stol.size();
  49.  
  50.         cout << "Stol nr " << stoly + 1 << ": ";
  51.  
  52.         for(unsigned i = 0; i < liczba_osob; ++i)
  53.             osoby[stol[i] - 1] = 0;
  54.  
  55.         // 5.
  56.         ++stoly;
  57.  
  58.         // 6.
  59.         usadzeni += liczba_osob;
  60.     }
  61.     cout << stoly << endl;
  62. }
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement