POJ 2271(HTML)

这题字符串处理

注意Seekeof会自动把后面的空格吃掉(有时遇到回车,后面会漏一个空格……貌似有时没空格也会读到,字符串处理时慎用

另外 空格的Ascii码是32,31及以下都是不可输入字符

program P2271;
var
   s:string;
procedure cin;
var
   c:char;
   i,len:longint;
begin
   s:='';
   c:=' ';
   i:=0;
   while not(seekeof) do
   begin
      read(c);
      while (ord(c)<=32) and not(eof) do read(c);
      if ord(c)<=32 then break;
      repeat
         s:=s+c;
         if eof then break;
         read(c);
      until (ord(c)<=32);

      len:=length(s);
      if s='<br>' then begin writeln; i:=0; end
      else
      if s='<hr>' then
      begin
         if i>0 then writeln;
         for i:=1 to 80 do write('-');
         writeln;
         i:=0;
      end
      else
      begin
         if (i=0) then
         begin
            if len<80 then
            begin
               write(s);
               i:=len;
            end;
         end
         else
         begin
            if (i+1+len<=80) then
            begin
               write(' ',s);
               i:=i+1+len;
            end
            else
            begin
               writeln;
               write(s);
               i:=len;

            end;
         end;

      end;

      s:='';
   end;

end;
begin
{   assign(input,'p2271.in');
   assign(output,'p2271.out');
   reset(input);
   rewrite(output);
 }  cin;
   writeln;
  { close(input);
   close(output);}
end.