Cod sursa(job #2498)

Utilizator alex_dincaDinca Alexandru-Nicolae - UPB alex_dinca Data 17 decembrie 2006 13:44:10
Problema Zeap Scor 10
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.91 kb
var v:array[1..300000] of longint;
    f,g:text;
    s,el:string;
    i,j,n,nr,x,k,max,min:longint;
    er:integer;
    sw:boolean;
begin
assign(f,'zeap.in');reset(f);
assign(g,'zeap.out');rewrite(g);
while not eof(f) do begin
      readln(f,s);
      if s[1]='I' then begin
         el:=copy(s,3,length(s));
         val(el,x,er);
         sw:=false;
         for i:=1 to n do
             if v[i]=x then sw:=true;
         if not sw then begin
            n:=n+1;
            v[n]:=x;
            end;
         end;{I}
      if s[1]='S' then begin
         el:=copy(s,3,length(s));
         val(el,x,er);
         sw:=false;
         for i:=1 to n do
             if v[i]=x then begin
                sw:=true;
                k:=i;
                end;
         if not sw then writeln(g,-1)
         else begin
              for i:=k to n-1 do
                  v[i]:=v[i+1];
              n:=n-1;
              end;
         end;{S}
      if s[1]='C' then begin
         el:=copy(s,3,length(s));
         val(el,x,er);
         sw:=false;
         for i:=1 to n do
             if v[i]=x then sw:=true;
         if sw then writeln(g,1)
         else writeln(g,0);
         end;{C}
      if (s[1]='M')and(s[2]='A')and(s[3]='X') then
         if n<2 then writeln(g,-1)
         else begin
              max:=-maxlongint;
              for i:=1 to n do
                for j:=1 to n do
                   if (i<>j)and(abs(v[i]-v[j])>max) then max:=abs(v[i]-v[j]);
              writeln(g,max);
              end;
      if (s[1]='M')and(s[2]='I')and(s[3]='N') then
         if n<2 then writeln(g,-1)
         else begin
              min:=maxlongint;
              for i:=1 to n do
                for j:=1 to n do
                   if (i<>j)and(abs(v[i]-v[j])<min) then min:=abs(v[i]-v[j]);
              writeln(g,min);
              end;
      end;{while};
close(g);
close(f);
end.