Language: C++


using namespace std;

void Main() {
    int N;
    cin >> N;
    vector<int> p(N, 0);
    for (int i = 0; i < N; ++i) {
        cin >> p[i];
        --p[i];
    }
    int ans = 0;
    for (int i = 0; i < N - 1; ++i) {
        if (p[i] == i) {
            swap(p[i], p[i + 1]);
            ++ans;
        }
    }
    if (p[N - 1] == N - 1) {
        swap(p[N - 1], p[N - 2]);
        ++ans;
    }
    cout << ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Compiler output:
a.cc: In function 'void Main()':
a.cc:6:5: error: 'cin' was not declared in this scope
    6 |     cin >> N;
      |     ^~~
a.cc:1:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
  +++ |+#include <iostream>
    1 | 
a.cc:7:5: error: 'vector' was not declared in this scope
    7 |     vector<int> p(N, 0);
      |     ^~~~~~
a.cc:1:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
  +++ |+#include <vector>
    1 | 
a.cc:7:12: error: expected primary-expression before 'int'
    7 |     vector<int> p(N, 0);
      |            ^~~
a.cc:9:16: error: 'p' was not declared in this scope
    9 |         cin >> p[i];
      |                ^
a.cc:14:13: error: 'p' was not declared in this scope
   14 |         if (p[i] == i) {
      |             ^
a.cc:15:13: error: 'swap' was not declared in this scope
   15 |             swap(p[i], p[i + 1]);
      |             ^~~~
a.cc:19:9: error: 'p' was not declared in this scope
   19 |     if (p[N - 1] == N - 1) {
      |         ^
a.cc:20:9: error: 'swap' was not declared in this scope
   20 |         swap(p[N - 1], p[N - 2]);
      |         ^~~~
a.cc:23:5: error: 'cout' was not declared in this scope
   23 |     cout << ans << endl;
      |     ^~~~
a.cc:23:5: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:23:20: error: 'endl' was not declared in this scope
   23 |     cout << ans << endl;
      |                    ^~~~
a.cc:1:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
  +++ |+#include <ostream>
    1 | 
a.cc: In function 'int main()':
a.cc:27:10: error: 'cout' is not a member of 'std'
   27 |     std::cout << std::fixed << std::setprecision(15);
      |          ^~~~
a.cc:27:10: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:27:23: error: 'fixed' is not a member of 'std'
   27 |     std::cout << std::fixed << std::setprecision(15);
      |                       ^~~~~
a.cc:1:1: note: 'std::fixed' is defined in header '<ios>'; this is probably fixable by adding '#include <ios>'
  +++ |+#include <ios>
    1 | 
a.cc:27:37: error: 'setprecision' is not a member of 'std'
   27 |     std::cout << std::fixed << std::setprecision(15);
      |                                     ^~~~~~~~~~~~
a.cc:1:1: note: 'std::setprecision' is defined in header '<iomanip>'; this is probably fixable by adding '#include <iomanip>'
  +++ |+#include <iomanip>
    1 |