ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1322. Spy

Help!Why WA???????
Posted by wangchun 2 May 2004 09:09
var sz,s,letter:array[1..100000]of char;
    num,nm:array[1..100000]of integer;
    c:array[65..122]of longint;
    n,m,t,k,l,p,q:longint;
begin
     fillchar(c,sizeof(c),0);
     fillchar(nm,sizeof(nm),0);
     fillchar(num,sizeof(num),0);
     readln(n);
     m:=0;
     while not eof do
           begin
                inc(m);
                read(sz[m]);
                inc(c[ord(sz[m])]);
           end;
     l:=0;
     for t:=65 to 122 do
         begin
              for k:=1 to c[t] do
                  begin
                       inc(l);
                       letter[l]:=chr(t);
                       num[l]:=c[t]-k+1;
                  end;
         end;
     s[n-1]:=sz[m];
     nm[n-1]:=num[m];
     l:=n-1;
     for k:=1 to m-1 do
         begin
              inc(l);
              q:=l-1;
              if l=m+1 then
                 begin
                      l:=1;
                      q:=m;
                 end;
              p:=0;
              for t:=m downto 1 do
                  if sz[t]=s[q] then
                     begin
                       inc(p);
                       if p=nm[q] then
                       begin
                          s[l]:=letter[t];
                          nm[l]:=num[t];
                          break;
                       end;
                     end;
         end;
     for t:=1 to m do
         write(s[t]);
end.