#include<stdio.h>
int main()
{
int n, l, i, j, k, count;
while(scanf("%d", &n) != EOF)
{
for(i=1;i<=n;i++)
{
count = 0;
scanf("%d", &l);
int a[l];
for(j=0;j<l;j++)
{
scanf("%d", &a[j]);
}
for(j=0;j<l;j++)
{
for(k=j+1;k<l;k++)
{
if(a[j]>a[k])
{
count++;
}
}
}
printf("Optimal train swapping takes %d swaps.\n", count);
}
}
return 0;
}
int main()
{
int n, l, i, j, k, count;
while(scanf("%d", &n) != EOF)
{
for(i=1;i<=n;i++)
{
count = 0;
scanf("%d", &l);
int a[l];
for(j=0;j<l;j++)
{
scanf("%d", &a[j]);
}
for(j=0;j<l;j++)
{
for(k=j+1;k<l;k++)
{
if(a[j]>a[k])
{
count++;
}
}
}
printf("Optimal train swapping takes %d swaps.\n", count);
}
}
return 0;
}
Comments
Post a Comment