#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define INF 0x3f3f3f3f
#define eps 1e-5
typedef long long LL;
const double pi = acos(-1.0);
const long long mod = 25 * 1E8;
using namespace std;
int a[200005];
int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
ios_base::sync_with_stdio(0);cin.tie(0);
int n;
cin >> n;
int ans = 0;
for(int i = 0;i < n;i++)
cin >> a[i];
for(int i = 0;i < n;i++)
for(int j = n - 1;j >= i + 1;j--)
if(a[j] < a[j - 1])
swap(a[j],a[j - 1]),ans++;
for(int k = 0;k < n - 1;k++)
printf("%d ",a[k]);
printf("%d\n",a[n - 1]);
printf("%d\n",ans);
return 0;
}
Aizu ALDS1_2_A Bubble Sort(冒泡排序)
最新推荐文章于 2019-09-13 15:08:25 发布