样例:
input:
5
1 5 2 3 4
output:
7 3 2
input:
5
1 3 2 5 4
output:
7 2 2
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=111111;
int maxx=-0x3f3f3f3f;
int n,a[maxn];
void bubblesort()
{
int cnt=0,cntt=0,cnt0=0;while(n>1){
int j=0;for(int i=1;i<n;i++){
cnt0++;//cout<<"cnt0="<<cnt0<<" "<<"i="<<i<<" "<<"n="<<n<<endl;if(a[i]>a[i+1]){
int t=a[i];a[i]=a[i+1];a[i+1]=t;j=i;//cout<<"j="<<j<<endl;cntt++;}}n=j;cnt++;}cout<<cnt0<<" "<<cntt<<" "<<cnt<<endl;
}
int main()
{
cin>>n;for(int i=1;i<=n;i++) cin>>a[i];bubblesort();
}