Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- int N, L, S, t[50], i, j, min;
- cin >> N;
- while (N--){
- cin >> L;
- for (int i = 0; i < L; i++)
- cin >> t[i];
- for (i = 0, S = 0; i < L - 1; i++){
- min = t[i];
- for (j = i + 1; j < L; j++){
- if (min > t[j]){
- S++;
- min = t[j];
- t[j] = t[i];
- t[i] = min;
- }
- }
- }
- cout << "Optimal train swapping takes " << S << " swaps." << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement