fork(1) 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. for (int i =1; i <= n; ++i) {
  10. cin >> v[i];
  11. }
  12. for (int i = 1; i <= n ; ++i) {
  13. int flag = 1;
  14. int destination = 1;
  15. for (int j = destination; j <= n; ++j ) {
  16. if(v[j] != i ) {
  17. destination = v[j];
  18. } else {
  19. ++zone;
  20. v[j] = 0;
  21. }
  22. }
  23. if(flag == 1) {
  24. v[i] = 0;
  25. }
  26. }
  27. cout << zone ;
  28. return 0;
  29. }
Success #stdin #stdout 0s 5296KB
stdin
11
11 1 7 8 10 3 9 2 5 6 4
stdout
6