uva 299

来源:互联网 发布:淘宝运营加薪申请 编辑:程序博客网 时间:2024/06/08 02:53
#include <stdio.h>int cases;int len;int tot;int store[55];int main(){int i, j;int tmp;scanf("%d", &cases);while(cases--){scanf("%d", &len);for(i = 0; i < len; i++){scanf("%d", &store[i]);}tot = 0;for(i = 0; i < len; i++){for(j = 0; j < len - i - 1; j++){if(store[j] > store[j+1]){tmp = store[j];store[j] = store[j+1];store[j+1] = tmp;++tot;}}}printf("Optimal train swapping takes %d swaps.\n", tot);}return 0;}

原创粉丝点击