Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
为什么总是WA呢,请各位大牛不吝赐教!#include<stdio.h> #include<string.h> #include<stdlib.h> int nums[1100]; int compare(const void* elem1,const void* elem2) { return (strcmp((char*)elem1,(char*)elem2)); } int main() { int T,t,n,k,i,j,flag,l; scanf("%d",&T); while(T--) { scanf("%d%d",&n,&k); for(i=0;i<n;i++) scanf("%d",nums+i); for(i=0;i<k;i++) { flag=1; for(j=n-1;j>0;j--) { if(nums[j-1]<nums[j]) { for(l=n-1;l>j-1;l--) if(nums[j-1]<nums[l]) break; flag=0; t=nums[j-1]; nums[j-1]=nums[l]; nums[l]=t; qsort(nums+j,n-j,sizeof(int),compare); break; } } if(flag) qsort(nums,n,sizeof(int),compare); } for(i=0;i<n-1;i++) printf("%d ",nums[i]); printf("%d\n",nums[n-1]); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator