Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int main() {
- int n, k, j, z, c, el;
- c = 0;
- k = 0;
- z = 0;
- std::vector <int> copy;
- std::vector <int> res;
- std::cin >> n;
- for (int i = 0; i < n; i++) {
- std::cin >> el;
- copy.push_back(el);
- res.push_back(el);
- }
- while (c != 1) {
- for (int i = 0; i < n; ++i) {
- j = copy[i];
- res[i] = copy[j]; }
- for (int i = 0; i < n; ++i) {
- copy[i] = res[i]; }
- for (int i = 0; i < n; ++i) {
- if (copy[i] == i) ++z; }
- if (z == n) c = 1;
- z = 0;
- k += 1;
- }
- std::cout << k;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement