Advertisement
noshin98

uva 299

Jul 5th, 2016
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.54 KB | None | 0 0
  1. #include<stdio.h>
  2. int main()
  3. {
  4. int i,j,k,t_case,n,t,train[51],count;
  5.       while(scanf("%d",&t_case)==1){
  6.          for(k=0;k<t_case;k++){
  7.     count=0;
  8.     scanf("%d",&n);
  9.     for(i=0;i<n;i++)
  10.         scanf("%d",&train[i]);
  11.  
  12.     for(i=0;i<n-1;i++)
  13.         for(j=0;j<n-1;j++)
  14.             if(train[j]>train[j+1]){
  15.                 count++;
  16.                 t=train[j];
  17.                 train[j]=train[j+1];
  18.                 train[j+1]=t;
  19.                 }
  20.     printf("Optimal train swapping takes %d swaps.\n",count);
  21.     }
  22. }
  23. return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement