3

你好,我有一个简单的程序,它在给定的文本中计算字符,直到行是空行,只有换行

var
  znaki: array['a'..'z'] of integer = (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
  napis: String;
  maly: String;
  dlugosc: Integer;
  znak: char;


begin
napis := 'a';
while napis[1] <> '#13#10'do
begin
  readln(napis);
  maly:=LowerCase(napis);
  for dlugosc:=(length(maly)) downto 1 do
begin
znaki[maly[dlugosc]]:=znaki[maly[dlugosc]]+1;
  end;
  for znak:='a' to 'z' do
    writeln(znak, ' ', znaki[znak]);
  end;

end.  

它在条件下失败,我不知道为什么。请给我线索

4

2 回答 2

2

一个字符,napis[ 1 ];不能是 2 个字符#13#10 ...

所以,我会这样做,例如:

var
  znaki: array['a'..'z'] of integer = (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
  napis: String;
  maly: String;
  dlugosc: Integer;
  znak: char;


begin
napis := 'a';
while ((Length(napis) > 0)) do
begin
  readln(napis);
//  napis := StringReplace(napis, #13#10, #10, [rfReplaceAll]);  //useless for a console readln
  maly:=LowerCase(napis);
  for dlugosc:=(length(maly)) downto 1 do
  begin
    znaki[maly[dlugosc]]:=znaki[maly[dlugosc]]+1;
  end;
  for znak:='a' to 'z' do
    writeln(znak, ' ', znaki[znak]);
end;
end.
于 2012-05-15T10:11:23.377 回答
2

#10是换行

#13是回车(即移动到行首)

您只需要检查#10。

于 2012-05-15T10:16:06.983 回答