Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4. int main() {
  5. int n, k, j, z, c, el;
  6. c = 0;
  7. k = 0;
  8. z = 0;
  9. std::vector <int> copy;
  10. std::vector <int> res;
  11. std::cin >> n;
  12. for (int i = 0; i < n; i++) {
  13. std::cin >> el;
  14. copy.push_back(el);
  15. res.push_back(el);
  16. }
  17. while (c != 1) {
  18. for (int i = 0; i < n; ++i) {
  19. j = copy[i];
  20. res[i] = copy[j]; }
  21. for (int i = 0; i < n; ++i) {
  22. copy[i] = res[i]; }
  23. for (int i = 0; i < n; ++i) {
  24. if (copy[i] == i) ++z; }
  25. if (z == n) c = 1;
  26. z = 0;
  27. k += 1;
  28. }
  29. std::cout << k;
  30. return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement