#include <iostream>
#define N 100
using namespace std;
int main() {
int i=0;
int vettore[N];
int temp, passaggi=0;
for ( i=0; i<N; i++){
vettore[i]=N-i;
}
// ordinamento con bubble sort
// Ciclo esterno ripetuto N-1 volte (99 volte)
for ( i=0; i<N-1; i++) {
// Ciclo interno: verificare le coppie e
// scambiare gli elementi
for (int j=0; j<N-i-1; j++) {
passaggi++;
if (vettore[j]>vettore[j+1]) {
temp = vettore[j];
vettore[j] = vettore[j+1];
vettore[j+1] = temp;
}
}
}
for ( i=0; i<N; i++) {
cout << vettore [i] << " ";
}
cout << endl << passaggi;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojZGVmaW5lIE4gMTAwCgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CglpbnQgaT0wOwoJaW50IHZldHRvcmVbTl07CglpbnQgdGVtcCwgcGFzc2FnZ2k9MDsKCWZvciAoIGk9MDsgaTxOOyBpKyspewoJCXZldHRvcmVbaV09Ti1pOwoJfQoJLy8gb3JkaW5hbWVudG8gY29uIGJ1YmJsZSBzb3J0CgkvLyBDaWNsbyBlc3Rlcm5vIHJpcGV0dXRvIE4tMSB2b2x0ZSAoOTkgdm9sdGUpCglmb3IgKCBpPTA7IGk8Ti0xOyBpKyspIHsKCQkvLyBDaWNsbyBpbnRlcm5vOiB2ZXJpZmljYXJlIGxlIGNvcHBpZSBlIAoJCS8vICAgICBzY2FtYmlhcmUgZ2xpIGVsZW1lbnRpCgkJZm9yIChpbnQgaj0wOyBqPE4taS0xOyBqKyspIHsKCQkJcGFzc2FnZ2krKzsKCQkJaWYgKHZldHRvcmVbal0+dmV0dG9yZVtqKzFdKSB7CgkJCQl0ZW1wID0gdmV0dG9yZVtqXTsKCQkJCXZldHRvcmVbal0gPSB2ZXR0b3JlW2orMV07CgkJCQl2ZXR0b3JlW2orMV0gPSB0ZW1wOwoJCQl9CgkJfQoJfQoJCglmb3IgKCBpPTA7IGk8TjsgaSsrKSB7CgkJY291dCA8PCB2ZXR0b3JlIFtpXSA8PCAiICI7Cgl9CQoJY291dCA8PCBlbmRsIDw8IHBhc3NhZ2dpOwoJcmV0dXJuIDA7Cn0K