-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path299.cpp
More file actions
39 lines (31 loc) · 625 Bytes
/
299.cpp
File metadata and controls
39 lines (31 loc) · 625 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
#include <iostream>
#include <vector>
#include <cstdint>
using namespace std;
int64_t loops;
int64_t num;
int64_t temp;
int64_t count;
int64_t trains[52];
int main() {
cin >> loops;
for (int64_t i = 0; i < loops; i++) {
count = 0;
cin >> num;
for (int64_t j = 0; j < num; j++) {
cin >> trains[j];
}
for (int64_t j = 0; j < num; j++) {
for (int64_t k = j + 1; k < num; k++) {
if (trains[j] > trains[k]) {
temp = trains[j];
trains[j] = trains[k];
trains[k] = temp;
count++;
}
}
}
cout << "Optimal train swapping takes " << count << " swaps." << endl;
}
return 0;
}