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:极度水题,贴代码(给不会用sort的菜鸟们)

Posted by lins03 at 2009-11-11 02:45:29 on Problem 3637
In Reply To:极度水题,贴代码(给不会用sort的菜鸟们) Posted by:bjtu1 at 2009-03-24 21:44:38
从2加起的话,n不是3的倍数的时候有错吧?

> 不说了,
> #include<stdio.h>
> #include<stdlib.h>
> 
> 
> int cmp( const void *e1, const void *e2){
> 	return *(int *)e2-*(int *)e1;
> };
> 
> int money[20001];
> 
> 
> int main()
> {
> 	int i;
> 	int n;
> 	int t,sum;
> 
> 	while(scanf("%d",&t)!=EOF){
> 		while(t--){
> 	sum=0;
> 	scanf("%d",&n);
> 	for(i=0;i<n;i++)
> 		scanf("%d",&money[i]);
> 	qsort(money,n,sizeof(money[0]),cmp);
> 
> 	for(i=2;i<n;i+=3)
> 		sum+=money[i];
> 	printf("%d\n",sum);
> 
> 	}
> 
> 	}
>     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