'commit'
This commit is contained in:
21
LuoGu/RuMen/P1116.cpp
Normal file
21
LuoGu/RuMen/P1116.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user