299 - Train Swapping

来源:互联网 发布:如何激活word for mac 编辑:程序博客网 时间:2024/05/16 05:07
#include <stdio.h>int main(){int N,L,carriages[50],count,temp;scanf("%d",&N);for(int i=0;i<N;i++){count=0;scanf("%d",&L);for(int j=0;j<L;j++)scanf("%d",&carriages[j]);for(int k=0;k<L;k++)for(int l=k+1;l<L;l++)if(carriages[k]>carriages[l]){temp=carriages[k];carriages[k]=carriages[l];carriages[l]=temp;count++;}printf("Optimal train swapping takes %d swaps.\n",count);}}

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=235
0 0
原创粉丝点击