Cod sursa(job #771266)

Utilizator ctlin04UAIC.VlasCatalin ctlin04 Data 25 iulie 2012 12:52:19
Problema Congr Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.95 kb
Program congr;
 type tip=record
      v,p:longint;
      end;
var a,b:array [1..300000] of tip;
    st,sc:int64;
    aux:tip;
    s:string;
    b1,b2:array [1..1 shl 17] of char;
    i,n,p1,p2,l,p:longint;
    fi,fo:text;
function citire:longint;
 var aux:longint;
begin
aux:=0;
 while (s[p]>='0') and (s[p]<='9') and (p<=l) do begin
                                            aux:=aux*10+ord(s[p])-48;
                                             if p=l then begin
                                                        read(fi, s);
                                                         p:=0;
                                                          l:=length(s);
                                                         end;
                                                      inc(p);
                                                  end;
 while ((s[p]<'0') or (s[p]>'9')) and (s<>'') do begin
                                                inc(p);
                                                if p>l then begin
                                                            read(fi, s);
                                                              p:=1;
                                                               l:=length(s);
                                                            end;
                                                  end;
citire:=aux;
end;
begin
 assign(fi,'congr.in');
  assign(fo,'congr.out');
 settextbuf(fi,b1); settextbuf(fo,b2);
 reset(fi); rewrite(fo); readln(fi,n);
 read(fi,s); l:=length(s); p:=1;
  for i:=1 to n do begin a[i].v:=citire; a[i].p:=i; sc:=sc+a[i].v; end;
   for i:=n+1 to 2*n-1 do begin b[i-n].v:=citire; b[i-n].p:=i; end;
 while sc mod n<>0 do begin
             p1:=random(n)+1;
             p2:=random(n-1)+1;
             sc:=sc-a[p1].v+b[p2].v;
             aux:=a[p1]; a[p1]:=b[p2]; b[p2]:=aux;
             end;
  for i:=1 to n do write(fo,a[i].p,' ');
 close(fo);
end.