Skip to content

Instantly share code, notes, and snippets.

@hu2di
Created April 10, 2017 02:45
Show Gist options
  • Save hu2di/e42ea7917e7e246182bf99aa73138189 to your computer and use it in GitHub Desktop.
Save hu2di/e42ea7917e7e246182bf99aa73138189 to your computer and use it in GitHub Desktop.
C++: lib
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int n;
int a[10001];
void input(){
scanf("%d", &n);
for(int i=1;i<=n;i++)
scanf("%d", &a[i]);
}
void khoi_tao(){
long dem;
int tg;
dem = 0;
for(int i=1;i<=n;i++)
for(int j=i+1;j<=n;j++)
if(a[i]>a[j]){
dem++;
tg = a[i];
a[i] = a[j];
a[j] = tg;
}
std::sort(a, a+n);
printf("%d", dem);
}
int main(){
input();
khoi_tao();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment