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

Re:qsort那个函数怎么用?哪位大虾帮忙看一下,谢了!

Posted by 20051610703 at 2010-02-15 13:50:47 on Problem 2782
In Reply To:qsort那个函数怎么用?哪位大虾帮忙看一下,谢了! Posted by:xiedf at 2006-03-28 20:57:33
#include <stdio.h>
#include <stdlib.h>
int cmp(const void *a,const void *b){return *(int*)a-*(int*)b;}
int A[10000];
int main()
{
	int N,M,i,j,re;
	scanf("%d%d",&N,&M);
	for(i=0;i<N;i++)scanf("%d",&A[i]);
	qsort(A,N,4,cmp);
	for(i=re=0,j=N-1;i<=j;j--)
	{
		if(A[i]+A[j]<=M)i++;
		re++;
	}
	printf("%d",re);
}

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