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 1183. Brackets Sequence

I have WA#9. Who knows where is my fault?
Posted by ¥@§@® Δδδ@$☺√ 27 Nov 2007 16:00
If who knows please tell me where is my mistake?

{PASCAL CODE HERE}
var
 t,st:string;
 i:integer;

procedure init;
begin
 readln(st);
 i:=0;  t:=st;
end;

procedure solve1;
begin
 repeat
  inc(i);
  if st[i]='(' then
   begin
    if ((pos(')',st)<>0) and (pos(')',st)>=i)) then
     begin
      st[i]:=' '; st[pos(')',st)]:=' ';
     end;
   end         else
  if st[i]=')' then
   begin
    if ((pos('(',st)<>0) and (pos('(',st)<=i)) then
     begin
      st[i]:=' '; st[pos('(',st)]:=' ';
     end;
   end         else
  if st[i]='[' then
   begin
    if ((pos(']',st)<>0) and (pos(']',st)>=i)) then
     begin
      st[i]:=' '; st[pos(']',st)]:=' ';
     end;
   end         else
  if st[i]=']' then
   begin
    if ((pos('[',st)<>0) and (pos('[',st)<=i)) then
     begin
      st[i]:=' '; st[pos('[',st)]:=' ';
     end;
   end;
 until i=length(st);
end;

procedure solve2;
begin
 i:=0;
 repeat
  inc(i);
  if st[i]='(' then
   begin
    insert(')',t,i+1); insert(' ',st,i+1); inc(i);
   end;
  if st[i]=')' then
   begin
    insert('(',t,i); insert(' ',st,i+1); inc(i);
   end;
  if st[i]='[' then
   begin
    insert(']',t,i+1); insert(' ',st,i+1); inc(i);
   end;
  if st[i]=']' then
   begin
    insert('[',t,i); insert(' ',st,i+1); inc(i);
   end;
 until i=length(st);
end;

procedure print;
begin
 writeln(t);
end;

begin
 init;
 solve1;
 solve2;
 print;
end.
Re: I have WA#9. Who knows where is my fault?
Posted by KIRILL(ArcSTUpid coder:) 27 Nov 2007 19:04
sorry, but your approach is incorrect
use dp

Edited by author 27.11.2007 19:05