hdu 4041 Eliminate Witches!

来源:互联网 发布:比价网站源码整站程序 编辑:程序博客网 时间:2024/04/29 13:24

用栈去模拟

弹栈出栈就做完了

当时还没转c

用p写的

 

program aaa;var sl,n,m,i,j,k,tb,tc,x:longint;    a:array[1..60000] of string;    b,c,t:array[1..1000000] of longint;    s,st:ansistring;    flag:boolean;beginreadln(k);for x:=1 to k do begin  fillchar(t,sizeof(t),0);  fillchar(c,sizeof(c),0);  fillchar(b,sizeof(b),0);  readln(s);  sl:=length(s);  while s[sl]=' ' do  dec(sl);  i:=1;st:='';m:=0;  n:=0;tb:=0;tc:=0;  while i<=sl do   begin    while (s[i]<>'(') and (s[i]<>')') and (s[i]<>',') and(i<=sl) do     begin      flag:=false;      st:=st+s[i];      i:=i+1;     end;     if (st<>'') then begin n:=n+1;a[n]:=st;tb:=tb+1;b[tb]:=n;m:=m+1;t[m]:=n;                         st:='';                       end;     if s[i]='(' then            begin             tc:=tc+1;c[tc]:=tb;            end;     if s[i]=')' then              begin               tb:=c[tc];               m:=m+1;               t[m]:=b[tb];               tc:=tc-1;               end;     if s[i]=',' then               begin                m:=m+1;                t[m]:=b[c[tc]];               end;    inc(i);   end;   writeln(n);   for i:=1 to n do    writeln(a[i]);   for i:=1 to m-1  do writeln(t[i],' ',t[i+1]);   writeln;  end; end.


 

原创粉丝点击