这题的教训是 要特判空串
Program P1951;
var
s:string;
len,i,j:longint;
b:array[0..10000] of boolean;
function isdight(x:longint):boolean;
begin
if (x>=65) and (x<=90) then exit(false);
if (x>=97) and (x<=122) then exit(false);
exit(true);
end;
begin
readln(s);
fillchar(b,sizeof(b),false);
b[ord('a')]:=true;
b[ord('e')]:=true;
b[ord('i')]:=true;
b[ord('o')]:=true;
b[ord('u')]:=true;
b[ord('A')]:=true;
b[ord('E')]:=true;
b[ord('I')]:=true;
b[ord('O')]:=true;
b[ord('U')]:=true;
i:=1;
while i<=length(s) do
begin
if b[ord(s[i])] and not(isdight(ord(s[i]))) then delete(s,i,1)
else
begin
b[ord(s[i])]:=true;
inc(i);
end;
end;
while (s[1]=' ') and (length(s)>=1) do delete(s,1,1);
while (s[length(s)]=' ') and (length(s)>=1) do delete(s,length(s),1);
i:=pos(' ',s);
while i<>0 do
begin
delete(s,i,1);
i:=pos(' ',s);
end;
i:=pos(' .',s);
while i<>0 do
begin
delete(s,i,1);
i:=pos(' .',s);
end;
i:=pos(' ,',s);
while i<>0 do
begin
delete(s,i,1);
i:=pos(' ,',s);
end;
i:=pos(' ?',s);
while i<>0 do
begin
delete(s,i,1);
i:=pos(' ?',s);
end;
writeln(s);
end.
本文通过一个具体的程序示例,展示了如何使用Pascal语言进行字符串处理,包括去除特定字符、处理空白字符及标点符号等,强调了对空字符串的特殊处理。
119

被折叠的 条评论
为什么被折叠?



