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