Files
python/LuoGu/RuMen/P1116.cpp

21 lines
467 B
C++
Raw Normal View History

2025-08-30 18:35:01 +08:00
#include <bits/stdc++.h>
using namespace std;
int jsq = 0, a[10001], n;//t储存要交换的车厢
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < n - 1; j++) {
if (a[j] > a[j + 1]) {
swap(a[j + 1], a[j]);
jsq++;//记录交换次数
}
}
}
cout << jsq;
return 0;
}