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 1345. HTML

Help WA#5!!!!!!!!!!!!
Posted by wyyyl 24 Dec 2006 11:39
I tried all the tests you gave in the board before, and I'm all right!!
But I still got WA#5. :(
Can you help me???
Please give me some tests or hints.
OR you can fix my code.

My code:

const span:array[1..4] of string=('comment>','keyword>','string>','number>');

   key:array[1..35] of string=('and','array','begin','case','class','const',
'div','do','else','end','for','function','if','implementation','interface',
'mod','not','of','or','procedure','program','record','repeat','shl','shr',
'string','then','to','type','unit','until','uses','var','with','while');

   sym=',./?<>\|=+-~!@#$%^&*()0987654321`{}[];:" '#39;
   sp='<span class='; se='</span>';

var st,sst:string;
   ch:char; i,hp:integer;
   comm,f:boolean;

function getnewword(var st:string):string;
var i:integer;
begin
   if pos(st[1],sym)<>0 then
   begin
      getnewword:=st[1];
      delete(st,1,1); exit;
   end;
   if comm then
   begin
      i:=pos('}',st);
      if i<>0 then
      begin
         write(copy(st,1,i),se);
         delete(st,1,i);
      end else begin
         write(st); st:='';
      end; exit('');
   end;
   for i:=1 to length(st) do
      if (pos(st[i],sym)<>0) then
      begin
         getnewword:=copy(st,1,i-1);
         delete(st,1,i-1); exit;
      end;
   getnewword:=st; st:='';
end;

procedure putspan(i:integer);
begin
   write(sp,span[i]);
end;

procedure putres(st:string);
begin
   putspan(2); write(st,se);
end;

function chkres(sst:string):boolean;
var i:integer; st:string;
begin
   st:=lowercase(sst);
   for i:=1 to 35 do
      if st=key[i] then exit(true);
   exit(false);
end;

procedure putsym(ch:char);
   procedure putnum(ch:char);
   begin
      putspan(4); write(ch); i:=1;
      repeat
         if st[i] in ['0'..'9'] then inc(i)
         else if st[i]='.' then
         begin
            f:=not f;
            if not f then break
            else inc(i);
         end else break;
      until 1=8;
      if st[i-1]='.' then dec(i);
      write(copy(st,1,i-1),se);
      delete(st,1,i-1);
   end;

   procedure putstr;
   begin
      putspan(3); write(#39); i:=pos(#39,st);
      write(copy(st,1,i),se); delete(st,1,i);
   end;

   procedure putchr;
   var i:integer;
   begin
      putspan(3); write('#'); i:=1; f:=false;
      while st[i] in ['0'..'9'] do inc(i);
      write(copy(st,1,i-1),se);
      delete(st,1,i-1);
   end;

   procedure putcom(ch:char);
   begin
      putspan(1); write(ch);
      if ch='/' then
      begin
         write(st,se); st:='';
      end else begin
         i:=pos('}',st);
         if i=0 then
         begin
            write(st); st:=''; comm:=true;
         end else begin
            write(copy(st,1,i),se);
            delete(st,1,i);
         end;
      end;
   end;
begin
   case ch of
      '0'..'9':putnum(ch); #39:putstr;
      '#':putchr; '{':putcom(ch);
      '/':if st[1]='/' then putcom(ch)
          else write(ch)
      else write(ch);
   end;
end;

procedure main;
begin
 {  assign(input,'1345.in'); reset(input);
   assign(output,'1345.out'); rewrite(output);}
   while not eof do
   begin
      readln(st);
      while st<>'' do
      begin
         sst:=getnewword(st);
         if comm then
         begin
            if sst='}' then
            begin
               write('}',se); comm:=false;
            end else begin
               hp:=pos('}',st);
               if hp=0 then
               begin
                  write(st); st:='';
               end else begin
                  write(copy(st,1,hp),se);
                  delete(st,1,hp); comm:=false;
               end;
            end; continue;
         end else if pos(sst[1],sym)<>0 then putsym(sst[1])
         else begin
            if chkres(sst) then putres(sst)
            else write(sst);
         end;
      end; writeln;
   end;
  { close(input);
   close(output);}
end;

begin
   comm:=false; main;
end.

Edited by author 24.12.2006 11:44