thoga31

Challenge 9 (Pascal)

Aug 13th, 2013
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.78 KB | None | 0 0
  1. program challenge9;
  2. type TLowAlpha = 'a'..'z';
  3. const LOWALPHA : set of char = ['a'..'z'];
  4.       DIGITS : set of char = ['0'..'9'];
  5.       FILE_NAME = 'challenge9_list.txt';
  6. var alpha : array[TLowAlpha] of byte = (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);
  7.     i : TLowAlpha;
  8.     sumdigit : smallint = 0;
  9.     f : text;
  10.     s : string = '';
  11.  
  12. begin
  13.     assign(f, FILE_NAME);
  14.     reset(f);
  15.     while not eof(f) do begin
  16.         readln(f, s);
  17.         if s[1] in DIGITS then
  18.             inc(sumdigit, ord(s[1]) - ord('0'))
  19.         else if s[1] in LOWALPHA then
  20.             inc(alpha[s[1]]);
  21.     end;
  22.     close(f);
  23.     writeln('Sum = ', sumdigit);
  24.     for i := 'a' to 'z' do
  25.         if alpha[i] <> 0 then
  26.             writeln(i, ' = ', alpha[i]);
  27.     readln;  // pausa
  28. end.
Advertisement
Add Comment
Please, Sign In to add comment