Pascal:为什么输出中有“dfsf”?

时间:2018-02-25 11:05:51

标签: pascal turbo-pascal

我们正在学校做帕斯卡,任务是让所有单词只有拉丁字符,这些单词在这些单词中按字母顺序递减。 所以我输入“sba dcb onml dfsf cba kl2 joh;”和programm输出“sba dcb onml dfsf cba”,这大​​部分是正确的,但我不知道为什么它包含“dfsf”,我该如何解决? P.S。:对不起我的英语。

    var
    u: string;
    ws: array[1..100] of string;
    w: string;
    len: integer;
    i, j, q, t, a, b, n, s, z: integer;
begin
    writeln('type string:');
    read(u);
    len := length(u);
    a := 1;
    i := 1;
    s := 1;
    while i <= len do
        if (u[i] >= '!') and (u[i] <= '~') then begin
            w := u[i];
            i := i + 1;
            while (i <= len) and
            ((u[i] >= '!') and
            (u[i] <= '~')) do begin
                w := w + u[i];
                i := i + 1;

                            for t := 1 to length(w) do begin
                              if not (w[t] in ['a'..'z']) then begin
                                s:= 0;
                                Break;
                              end else begin
                              s:= s + 1;

                                n:=length(w);
                                for a:=1 to n-1 do
                                for b:=a+1 to n do
                                  if not (w[a] >= w[b]) then
                                  begin
                                    s:=0;
                                  end else begin
                                  s:= s + 1;
                                  end;

                              end;
                            end;




            end;


                if s<>0 then begin
                q:= q + 1;
                ws[q] := w;
                end;
        end
        else
            i := i + 1;

    for i := 1 to q do
        writeln(ws[i]);

end.

1 个答案:

答案 0 :(得分:0)

当有一对下降字母字符时,意识到该部分正在增加变量,所以我就把它删除了。

else begin
s:= s + 1;
end;
相关问题