pascal問題 (點樣記錄一d字出現ge次數)

2007-07-26 12:16 am
我用assign同reset read左一篇文 跟住我想記錄一下一d特定字ge次數(係字 唔係字母) 好似"the"咁 到底要點打呢??

回答 (1)

2007-07-27 10:15 am
✔ 最佳答案
Var i,total,j:integer;
s:string[30];
a:array[1..30] of char;
table:array[1..200] of string;
count:array[1..200] of integer;
c:char;
found:boolean;
f:text;
begin
assign(f,'count.txt');
reset(f);
total:=0;
j:=0;
while not eof(f) do
repeat
s:=' ';
repeat
j:=j+1;
read(f,c);
a[j]:=c;
Until c<'A';
for i:=1 to j-1 do
s[i]:=a[i];
s:=s+' ';
found:=false;
for i:=1 to total do
If table[i]=s then
begin
count[i]:=count[i]+1;
found:=true;
end;
If (not found) and (s<>' ') then
begin
table[total+1]:=s;
count[total+1]:=1;
total:=total+1;
end;
for i:=1 to j do
a[i]:=' ';
j:=0;
Until eoln(f);
for i:= 1 to total do
writeln(table[i],' ',count[i]);
writeln('Total no. of distinct word:',total);
close(f);
end.
參考: My brain


收錄日期: 2021-04-13 17:33:34
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20070725000051KK03064

檢視 Wayback Machine 備份