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

晕了 搞不懂题~~~负数不计算在内的吧?如果必须出一个人,要考虑全是负数的情况 哪里错了?帮忙看看

Posted by gucun4848 at 2008-07-20 19:34:51 on Problem 2209
#include<stdio.h>
#include<math.h>
int main()
{
    int n,p,i,a[101],min=-100000,flag=0;
    double sum=0;
    scanf("%d%d",&n,&p);
    for(i=0;i<n;i++)
      {
      scanf("%d",&a[i]);
      if(a[i]>=0)
        {
        sum+=pow((double)a[i],(double)p);
        flag=1;
        }
      else
        if(a[i]>min)
          min=a[i];
      }
    if(flag)
      printf("%d\n",(int)sum);
    else
      printf("%d\n",(int)pow((double)min,(double)p));
    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