朱色虫居
Pages
Home
Featured Posts
2006/09/26
299-Train Swapping
/*
"Train Swapping"
Level:1.0
Date:2006/9/25
技巧:Bubble sort
*/
#include
#define LEN 51
main(){
int n=0,length=0,i=0,j=0,tmp=0,count=0;
int train[LEN]={0};
scanf("%d",&n);
while(n-- > 0){
scanf("%d",&length);
for(i=0;i < length;i++) scanf("%d",&train[i]); for(i=0;i < length;i++){ for(j=i+1;j < length;j++){ if(train[i] > train[j]){
tmp = train[i];
train[i]=train[j];
train[j]=tmp;
count++;
}
}
}
printf("Optimal train swapping takes %d swaps.\n",count);
count=0;
}
}
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment