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

1AC PASCAL

Posted by aiouniya at 2012-08-28 16:52:52 on Problem 1552
var i,j,n,m,sum:integer;
    a:array[1..100]of integer;
procedure sort(l,r: longint);
      var
         i,j,x,y: longint;
      begin
         i:=l;
         j:=r;
         x:=a[(l+r) div 2];
         repeat
           while a[i]<x do
            inc(i);
           while x<a[j] do
            dec(j);
           if not(i>j) then
             begin
                y:=a[i];
                a[i]:=a[j];
                a[j]:=y;
                inc(i);
                j:=j-1;
             end;
         until i>j;
         if l<j then
           sort(l,j);
         if i<r then
           sort(i,r);
      end;
begin
  read(n);
  while n<>-1 do begin
  fillchar(a,sizeof(a),0);
  i:=1;
  sum:=0;
  while n<>0 do begin
    a[i]:=n;
    inc(i);
    read(n);
  end;
  dec(i);
  sort(1,i);
  for j:=1 to i do
      for m:=j to i do
        if a[j]*2=a[m] then  begin  inc(sum);break; end;
  writeln(sum);
  read(n);
  end;
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