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

sort函数我是不是用错了?

Posted by argforever at 2005-03-08 21:24:02 on Problem 2209
#include<stdio.h>
#include<algorithm>
bool cmp(int i,int j)
{
	return i>j;
}
int power(int i,int e)
{
	int r=1;
	for(int j=0;j<e;j++)
		r*=i;
	return r;
}
void main()
{
	int n,e,r[105],t,total=0;
	scanf("%d",&n);
	scanf("%d",&e);
	for(int i=0;i<n;i++){
		scanf("%d",&t);
		r[i]=power(t,e);
	}
	std::sort(r,r+n,cmp);
	i=0;
	while(r[i]>0) total+=r[i++];
	printf("%d\n",total);
}
为什么WA,不用sort就能AC

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