Created
April 10, 2017 02:45
-
-
Save hu2di/e42ea7917e7e246182bf99aa73138189 to your computer and use it in GitHub Desktop.
C++: lib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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