You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
447 B
21 lines
447 B
2 years ago
|
#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;
|
||
|
}
|