Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // wersja ostateczna
- #include <iostream>
- #include <vector>
- using namespace std;
- unsigned kto_na_prawo(unsigned nr_osoby, unsigned* osoby)
- {
- return osoby[nr_osoby - 1];
- }
- unsigned znajdz_pierwsza(unsigned* osoby)
- {
- for(int i = 0; true; ++i)
- if(osoby[i] != 0)
- return i + 1;
- }
- int main()
- {
- unsigned n;
- cin >> n;
- // 1.
- unsigned osoby[n];
- for(unsigned i = 0; i < n; ++i)
- cin >> osoby[i];
- // 2.
- vector<unsigned> stol;
- unsigned usadzeni = 0, x, liczba_osob, stoly = 0;
- // 3.
- while(usadzeni < n)
- {
- stol.clear();
- stol.push_back(znajdz_pierwsza(osoby));
- x = kto_na_prawo(stol[0], osoby);
- while(x != stol[0])
- {
- stol.push_back(x);
- x = kto_na_prawo(stol[stol.size() - 1], osoby);
- }
- // 4.
- liczba_osob = stol.size();
- cout << "Stol nr " << stoly + 1 << ": ";
- for(unsigned i = 0; i < liczba_osob; ++i)
- osoby[stol[i] - 1] = 0;
- // 5.
- ++stoly;
- // 6.
- usadzeni += liczba_osob;
- }
- cout << stoly << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement