P1116 车厢重组

题目传送门

#include <bits/stdc++.h>

using namespace std;
const int N = 10010;
int a[N];
int n, cnt;

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];

    for (int i = 1; i < n; i++)
        for (int j = i + 1; j <= n; j++)
            if (a[i] > a[j]) {
                cnt++;
                swap(a[i], a[j]);
            }
    cout << cnt << endl;
    return 0;
}
posted @ 2021-11-23 14:48  糖豆爸爸  阅读(76)  评论(0编辑  收藏  举报
Live2D