#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
int bubbleSort(int *A, int N){
int flag=1,count=0;
while(flag){
flag=0;
for(int j=N-1;j>0;j--){
if(A[j]<A[j-1]){
std::swap(A[j],A[j-1]);
flag=1;
count++;
}
}
}
return count;
}
int main() {
// your code goes here
int N,A[101];
scanf("%d",&N);
for(int i=0;i<N;i++){
scanf("%d",&A[i]);
}
int c=bubbleSort(A,N);
for(int i=0;i<N;i++){
if(i>0)printf(" ");
printf("%d",A[i]);
}
printf("\n%d\n",c);
return 0;
}
最終更新:2016年03月30日 06:45