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

唔唔唔。。。这道题为什么Pascal编的过不了。。。c的可以。。。。???那位好心帮我看看。。

Posted by harryhwy at 2007-07-26 20:23:59 on Problem 2623
#include <stdio.h>
#include <math.h>
#define N 250000
long a[N];
long p(long l,long r)
{
   long i=l-1,j=r+1,tmp=a[l],tmp2;
   while(i<j) 
   {
      while(a[++i]<tmp);
      while(a[--j]>tmp);
      if(i<j)
      {
          tmp2=a[i];
          a[i]=a[j];
          a[j]=tmp2;       
      }          

   } 
    return j;


}
void qsort(long l,long r)
{
   long mid; 
   if(l<r)
   {
     mid=p(l,r);
     qsort(l,mid);
     qsort(mid+1,r);      
   }  
}




int main()
{
   long n,i;
   double result; 
   scanf("%ld",&n);
   for(i=1;i<=n;i++)
       scanf("%ld",&a[i]);
   qsort(1,n);
   if(n%2==1)
     printf("%ld.0\n",a[(n+1)/2]);
   else 
   {
       result=1.0*a[n/2]+1.0*a[(n+2)/2];
       result/=2.0;
       printf("%.1lf\n",result)   ;
   }    
   return 0;
}





program p2623;
 var n:longint;
     num:array[1..250000]of longint;

 procedure init;
  var i:longint;
  begin
   readln(n);
   for i:=1 to n do
    readln(num[i]);
  end;

 procedure qsort(l,r:longint);
  var i,j,mid,s:longint;
  begin
   i:=l;j:=r;mid:=num[(l+r) div 2];
   repeat
    while num[i]<mid do inc(i);
    while num[j]>mid do dec(j);
    if i<=j then begin
                  s:=num[i];
                  num[i]:=num[j];
                  num[j]:=s;
                  inc(i); dec(j);
                 end;
   until i>j;
   if l<j then qsort(l,j);
   if i<r then qsort(i,r);
  end;

 procedure main;
  var ou:extended;
  begin
   if n mod 2=1 then writeln(num[(n+1)div 2],'.0')
                else begin
                      ou:=(num[n div 2]+num[n div 2+1])/2;
                      writeln(ou:0:1);
                     end;
  end;

 begin
  init;
  qsort(1,n);
  main;
 end.



有什么不同么?







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