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

Please, Help!!! WA on test #1! It's impossible!
Posted by Pasha 4 Jul 2004 21:40
Deleted because of the 4th rule!
Bad moderator ;)

Edited by author 14.07.2004 01:21
Re: Please, Help!!! WA on test #1! It's impossible!
Posted by LeXuS[Alex Kalugin] 11 Jul 2004 20:18
HERE!!!
const
maxlen=100001;{Maximal message length}
nalfa=256;{Symbols in alphabet}
rasset: set of char=['A'..'Z', '_', 'a'..'z'];
var
countmas: array [#0..#255] of longint;
{Quantity of each char in message, from #0 to #255}
t: array [0..maxlen] of longint;
{Backward vector}
inblock: array [0..maxlen] of char;
{"Encoded" message}
len,{current message length}
posit,{position of initial message in the sorted list}
i,{simple counter}
sum: longint;
ch: char;
begin
readln(posit);
dec(posit);
{===Initializing the arrays and other variables===}
len:=0;
fillchar(countmas, sizeof(countmas), 0);
fillchar(t, sizeof(t), 0);
fillchar(inblock, sizeof(inblock), 0);
{===reading encoded message===}
while (not seekeof) do
begin
read(ch);
inc(len);
inblock[len-1]:=ch;
end;
{===Counting symbols in message===}
for i:=0 to len-1 do
inc(countmas[inblock[i]]);
{===Starting sorting symbols to make backward vector T===}
sum:=0;
for i:=0 to nalfa-1 do
begin
inc(sum, countmas[chr(i)]);
countmas[chr(i)]:=sum-countmas[chr(i)]
end;
{===Calculating backward vector T===}
for i:=0 to len-1 do
begin
t[countmas[inblock[i]]]:=i;
inc(countmas[inblock[i]])
end;
{===Writing out "decoded" (initial) message===}
for i:=0 to len-1 do
begin
posit:=t[posit];
write(inblock[posit])
end
end.

I write: seekeof(not eof) ;~)))