https://vjudge.net/problem/UVA-299
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cctype>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
using namespace std;
const int N=55;
int a[N];
int main(){
int n;
scanf("%d",&n);
while(n--){
int m;
scanf("%d",&m);
memset(a,0,sizeof(a));
for(int i=0;i<m;i++)
scanf("%d",a+i);
bool have=true;
int ans=0;
while(have){
have=false;
for(int i=0;i<m-1;i++)
if(a[i]>a[i+1]){
swap(a[i],a[i+1]);
have=true;
ans++;
}
if(!have)break;
}
printf("Optimal train swapping takes %d swaps.\n",ans);
}
}