MK

Monday, 26 March, 2007

Files Quiz 2 建議答案

Filed under: CIT Module A,CIT2008 — MK @ 16:25

Files Quiz 2 的答案︰

program CountLetters(input, output);
var
fi, fo: text;
ch: char;
filename: string;
freq: array['a'..'z'] of integer;
begin
for ch := 'a' to 'z' do
freq[ch] := 0;
write('Input file? ');
readln(filename);
assign(fi, filename);
reset(fi);
while not eof(fi) do begin
while not eoln(fi) do begin
read(fi, ch);
if (ch >= 'A') and (ch <= 'Z') then
ch := chr(ord(ch) + 32);
if (ch >= 'a') and (ch <= 'z') then
freq[ch] := freq[ch] + 1
end;
readln(fi)
end;
close(fi);
assign(fo, 'RESULT.TXT');
rewrite(fo);
for ch := 'a' to 'z' do
writeln(fo, ch, '-', freq[ch]);
close(fo);

writeln('Done!')
end.

2 Comments »

  1. 唔想用eoln() …

    Comment by chutung — Tuesday, 27 March, 2007 @ 00:27 | Reply

  2. 唔想用但一定要用..
    因本身果個test data有幾行超過了256個字元..

    Comment by Stanford — Saturday, 31 March, 2007 @ 21:09 | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.