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 1220. Stacks

why wrong answer 10 test???? Help please++++++++
Posted by Виктор Крупко 29 Apr 2005 00:35
program de;
    var
    a:array[0..100000] of longint;
    b:array[0..100000] of word;
    c:array[0..1000] of longint;
    i,j,n,x,y,z:longint;
    code:integer;
    s:string;
begin
    readln(n);
    for i:=1 to n do
     begin
       readln(s);
       if (pos('PUSH',s)<>0) then
        begin
         inc(z);
         delete(s,1,5);
         for j:=1 to length(s) do if s[j]=' ' then break;
         val(copy(s,1,j-1),x,code);
         val(copy(s,j+1,length(s)-j),y,code);
         inc(z);
         a[z]:=y;
         b[z]:=c[x];
         c[x]:=z;
        end
       else
         begin
          delete(s,1,4);
          val(s,x,code);
          writeln(a[c[x]]);
          c[x]:=b[c[x]];
         end;
     end;
end.
Re: why wrong answer 10 test???? Help please++++++++
Posted by ZiV 11 Jan 2006 22:43
I made one change....and got TLE....
var
a:array[0..100000] of longint;
b:array[0..100000] of word;
c:array[0..1000] of longint;
i,j,n,x,y,z:longint;
code:integer;
s:string;
begin
readln(n);
for i:=1 to n do
begin
readln(s);
if (pos('PUSH',s)<>0) then
begin
inc(z);
delete(s,1,pos('PUSH',s)+4);
for j:=1 to length(s) do if s[j]=' ' then break;
val(copy(s,1,j-1),x,code);
val(copy(s,j+1,length(s)-j),y,code);
inc(z);
a[z]:=y;
b[z]:=c[x];
c[x]:=z;
end
else
begin
delete(s,1,pos('POP',s)+3);
val(s,x,code);
writeln(a[c[x]]);
c[x]:=b[c[x]];
end;
end;
end.