'commit'
This commit is contained in:
25
TangDou/XiTi/1123.cpp
Normal file
25
TangDou/XiTi/1123.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
int n, c;
|
||||
cin >> n;
|
||||
vector<int> v1;
|
||||
for (int i = 0; i < n; ++i) {
|
||||
cin >> c;
|
||||
v1.push_back(c);
|
||||
}
|
||||
int count = 0;
|
||||
//冒泡排序,计算步数
|
||||
for (int i = 0; i < n - 1; ++i) {
|
||||
for (int j = 0; j < n - 1 - i; ++j) {
|
||||
if (v1[j] > v1[j + 1]) {
|
||||
swap(v1[j], v1[j + 1]);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
cout << count << endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user