关于一道pascal题目读入一个字串,删去字串中相同的字符.这道题如下编写为什么不对?program qp1765;vars:string;i,j,n:integer;beginreadln(s);n:=length(s);for i:=1 to n dofor j:=i+1 to n doif copy(s,i,1)=copy(s,j,1) then dele
来源:学生作业帮助网 编辑:作业帮 时间:2024/07/13 09:15:52
![关于一道pascal题目读入一个字串,删去字串中相同的字符.这道题如下编写为什么不对?program qp1765;vars:string;i,j,n:integer;beginreadln(s);n:=length(s);for i:=1 to n dofor j:=i+1 to n doif copy(s,i,1)=copy(s,j,1) then dele](/uploads/image/z/1581770-2-0.jpg?t=%E5%85%B3%E4%BA%8E%E4%B8%80%E9%81%93pascal%E9%A2%98%E7%9B%AE%E8%AF%BB%E5%85%A5%E4%B8%80%E4%B8%AA%E5%AD%97%E4%B8%B2%2C%E5%88%A0%E5%8E%BB%E5%AD%97%E4%B8%B2%E4%B8%AD%E7%9B%B8%E5%90%8C%E7%9A%84%E5%AD%97%E7%AC%A6.%E8%BF%99%E9%81%93%E9%A2%98%E5%A6%82%E4%B8%8B%E7%BC%96%E5%86%99%E4%B8%BA%E4%BB%80%E4%B9%88%E4%B8%8D%E5%AF%B9%3Fprogram+qp1765%3Bvars%3Astring%3Bi%2Cj%2Cn%3Ainteger%3Bbeginreadln%28s%29%3Bn%3A%3Dlength%28s%29%3Bfor+i%3A%3D1+to+n+dofor+j%3A%3Di%2B1+to+n+doif+copy%28s%2Ci%2C1%29%3Dcopy%28s%2Cj%2C1%29+then+dele)
关于一道pascal题目读入一个字串,删去字串中相同的字符.这道题如下编写为什么不对?program qp1765;vars:string;i,j,n:integer;beginreadln(s);n:=length(s);for i:=1 to n dofor j:=i+1 to n doif copy(s,i,1)=copy(s,j,1) then dele
关于一道pascal题目
读入一个字串,删去字串中相同的字符.这道题如下编写为什么不对?
program qp1765;
var
s:string;
i,j,n:integer;
begin
readln(s);
n:=length(s);
for i:=1 to n do
for j:=i+1 to n do
if copy(s,i,1)=copy(s,j,1) then delete(s,j,1);
writeln(s);
end.
关于一道pascal题目读入一个字串,删去字串中相同的字符.这道题如下编写为什么不对?program qp1765;vars:string;i,j,n:integer;beginreadln(s);n:=length(s);for i:=1 to n dofor j:=i+1 to n doif copy(s,i,1)=copy(s,j,1) then dele
错误原因:你把第j位置上的直接删除,这时,第j+1位置上的字符就随之移到第j位上了,而你没有对这个字符进行检查,直接进入了下一个字符,因此存在漏网之鱼.由于j为循环变量,不方便在循环体中更改,所以我帮你这样改了一下,测试通过:
program qp1765;
var
s:string;
i,j,n:integer;
begin
readln(s);
n:=length(s);
for i:=1 to n do
begin
j:=i+1;
while j