提交时间:2023-01-12 15:55:47
运行 ID: 17817
#include <iostream> #include <cstdio> #include <algorithm> using namespace std; int main() { int n; cin >> n; int cows[100], sorted[100]; for (int i = 0; i < n; i++) { cin >> cows[i]; sorted[i] = cows[i]; } sort(sorted, sorted + n); int swaps = 0; for (int i = 0; i < n; i++) { if (cows[i] != sorted[i]) { swaps++; } } cout << swaps - 1 << endl; return 0; }