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

大牛们 help me!!! 到底错在哪? 我要崩溃了。。。

Posted by yueyue at 2006-08-07 17:29:58 on Problem 2231
#include<iostream>
using namespace std;
#define M 10000
int a[M];
int sort(int a[],int n)
{
	int  temp;
	for(int i=0;i<n;i++)
		for(int k=i+1;k<n;k++)			
			if(a[i]>a[k])
			{
				temp=a[k];
				a[k]=a[i];
				a[i]=temp;
			}
			return 0;		
}
int main()
{
	int n,i,j;
    long s=0;
	cin>>n;				
	for(i=0;i<n;i++)
		cin>>a[i];
	sort(a,n);
	for(i=0;i<n;i++)
	{
	for(j=i+1;j<n;j++)
			s+=a[j];
         }
		for(i=0;i<n-1;i++)
		{
	  for(j=0;j<i+1;j++)
				s-=a[j];	
      }			
			cout<<2*s<<endl;
	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