//冒泡排序
#include <bits/stdc++.h>
using namespace std;
int n;
int cnt;
int a[10010];
int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for (int i = 1; i < n; i++) {
		bool f = false;
		for (int j = 1; j <= n - i; j++) {
			if (a[j] > a[j + 1]) {
				swap(a[j], a[j + 1]);
				f = true;
				cnt++;
			}
		}
		if (!f)break;
	}
	cout << cnt << endl;
	return 0;
}

0 条评论

目前还没有评论...

信息

ID
311
时间
ms
内存
MiB
难度
2
标签
递交数
349
已通过
136
上传者