Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

为什么总是WA呢,请各位大牛不吝赐教!

Posted by wlyayjh at 2009-10-12 22:12:12 on Problem 1833
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator