Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
大牛们 help me!!! 到底错在哪? 我要崩溃了。。。#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator