|
|
back to boardDiscussion of Problem 1322. SpyHelp!Why WA??????? 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. |
|
|