-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuva-10327.cpp
More file actions
44 lines (32 loc) · 895 Bytes
/
uva-10327.cpp
File metadata and controls
44 lines (32 loc) · 895 Bytes
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
#include <bits/stdc++.h>
using namespace std;
int main()
{
freopen("in.txt","r",stdin);
freopen("out.txt","w", stdout);
int n, i, temp, minCount, swaps, data[1000];
bool sorted;
while (scanf("%d", &n) != EOF) {
for (i = 0; i < n; i++) {
scanf("%d", &data[i]);
}
minCount = 0;
while (true) {
swaps = 0;
for (i = 0; i < n - 1; i++) {
if (data[i] > data[i + 1]) {
temp = data[i];
data[i] = data[i + 1];
data[i + 1] = temp;
swaps++;
}
}
minCount += swaps;
if (swaps == 0) {
break;
}
}
printf("Minimum exchange operations : %d\n", minCount);
}
return 0;
}