fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int MAX_SIZE = 1000;
  5. int main() {
  6. int n, v[MAX_SIZE + 1];
  7. cin >> n;
  8. int zone = 0;
  9. int flag = 0;
  10. for (int i =1; i <= n; ++i) {
  11. cin >> v[i];
  12. }
  13. for (int i = 1; i <= n; ++i) {
  14. flag = 0;
  15. for (int j = 1; j <= n && flag == 0; ++j) {
  16.  
  17. if (v[i] == j) {
  18. //flag = 1;
  19. j = v[i];
  20. // cout << j <<" ";
  21. }
  22. if( v[j] == i) {
  23. cout << v[j] <<" ";
  24. // v[j] = 0;
  25. }
  26. }
  27.  
  28. }
  29. cout << zone ;
  30. return 0;
  31. }
Success #stdin #stdout 0s 5300KB
stdin
9
4 2 9 1 3 7 8 6 5
stdout
1 2 3 4 5 6 7 8 9 0