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:哪里不对了 请帮忙 谢谢

Posted by gucun4848 at 2008-07-20 10:20:59 on Problem 3637
In Reply To:哪里不对了 请帮忙 谢谢 Posted by:gucun4848 at 2008-07-20 10:20:33
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[20005];
int main()
{
    int i,j,n,k,sum;
    scanf("%d",&k);
    for(j=1;j<=k;j++)
      {
      sum=0;
      scanf("%d",&n);
      for(i=0;i<n;i++)
        scanf("%d",&a[i]);
      sort(a,a+n);
      if(n%3==1)
        {
        sum+=a[0];
        for(i=1;i<n;i=i+3)
          sum+=a[i];
        printf("%d\n",sum);    
        }               
      else if(n%3==2)
        {
        sum+=a[0]+a[1];
        for(i=2;i<n;i=i+3)
          sum+=a[i];  
        printf("%d\n",sum);         
        }
      else
        {
        for(i=0;i<n;i=i+3)
          sum+=a[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