-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBrainman.c
46 lines (40 loc) · 875 Bytes
/
Brainman.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include<stdio.h>
void swap(int s[], int i, int j);
int brainman(int a[], int n);
int main()
{
int n[1001], aa[1001], m, a[1001], j, i;
scanf("%d", &m);
for(j = 0; j < m; j++){
scanf("%d", &n[j]);
for(i = 0; i < n[j]; i++){
scanf("%d", &a[i]);
}
int cnt = brainman(a, n[j]);
printf("Scenario #%d:\n%d\n\n", j + 1, cnt);
}
return 0;
}
int brainman(int a[], int n){
int cnt = 0;
for(int i = 0; i < n - 1; i++){
int flag = 0;
for(int j = n - 1; j >= i + 1; j--){
if(a[j] < a[j - 1]){
swap(a, j - 1, j);
cnt++;
flag = 1;
}
}
if(!flag){
break;
}
}
return cnt;
}
void swap(int s[], int i, int j){
int temp;
temp = s[i];
s[i] = s[j];
s[j] = temp;
}