4. 删除其它字符

program ex_4;
var
     st : string;
     i, len : integer;
begin
     readln(st);
     len := length(st);
     i := len;
     while i >= 1 do
     begin
          if (st[i] < 'A') or ((st[i] > 'Z') and (st[i] < 'a')) or (st[i] > 'z') then
             delete(st, i, 1);
          i := i-1;
     end;
     writeln(st);
     readln;
end.


program ex_4;
var
     st : string;
     i, j, len : integer;
begin
     readln(st);
     len := length(st);
     j := 1;
     for i := 1 to len do
          if ((st[i] >= 'A') and (st[i] <= 'Z')) or ((st[i] >= 'a')) and (st[i] <= 'z') then
          begin
               if (i <> j) then
                  st[j] := st[i];
               j := j+1;
          end;
     st[0] := chr(j-1);
     writeln(st);
     readln;
end.
posted @ 2010-03-14 19:16  SmartIOI  阅读(117)  评论(0)    收藏  举报
本站采用CC授权如需转载、引用文章,请务必附上作者及来源处。 Creative Commons License