1

我们在学校里做帕斯卡,任务是得到所有只有拉丁字符的单词,这些单词在这些单词中按字母顺序排列。所以我输入“sba dcb onml dfsf cba kl2 joh;” 并且程序的输出为“sba dcb onml dfsf cba”,这基本上是正确的,但我不明白为什么它包含“dfsf”,我该如何解决?PS:对不起我的英语。

    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.
4

1 回答 1

0

意识到当有一对按字母顺序排列的字符时,该部分正在增加变量(s),所以我将其删除。

else begin
s:= s + 1;
end;
于 2018-02-25T12:58:55.637 回答