Follows 299.c (Total 28 lines):

/* @JUDGE_ID:4461XX 299 C */
/* A */
#include <stdio.h>
int b,i,j,k,number,m,n,times,temp;
int a[50];
void main(void)
{
	scanf("%d",&b);
	for(i=1;i<=b;i++)
	{
		scanf("%d",&number);
		for(j=0;j<50;j++)a[j]=0;
		for(j=0;j<number;j++)
		{
			scanf("%d",&k);
			a[j]=k;
		}
		times=0;
		for(m=0;m<number;m++)
			for(n=m;n<number;n++)
				if(a[m]>a[n])
				{
					temp=a[m];a[m]=a[n];a[m]=temp;
					times++;
				}
				printf("Optimal train swapping takes %d swaps.\n",times);
	}
}

Back to statistics
Ya-Lin Huang (C)
huangyl@gmail.com