The_Law

Untitled

Dec 14th, 2017
402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.75 KB | None | 0 0
  1. program ideone;
  2.  
  3. var
  4. cnt: array[1..26, 1..26] of integer;
  5. i, j, itf, its: integer;
  6. c: char;
  7. s: string;
  8.  
  9. begin
  10.     for i := 1 to 26 do
  11.         for j := 1 to 26 do
  12.             cnt[i][j] := 0;
  13.    
  14.     read(s);
  15.    
  16.     for i := 1 to length(s) do
  17.     begin
  18.         if (s[i] = ',') or (s[i] = '.') then
  19.         begin
  20.             j := i - 1;
  21.            
  22.             while (j >= 1) and (s[j] <> ',') do
  23.                 j := j - 1;
  24.            
  25.             cnt[ord(s[j + 1]) - ord('a') + 1][ord(s[i - 1]) - ord('a') + 1] :=
  26.             cnt[ord(s[j + 1]) - ord('a') + 1][ord(s[i - 1]) - ord('a') + 1] + 1;
  27.         end;
  28.     end;
  29.    
  30.     itf := 1;
  31.     its := 1;
  32.    
  33.     for i := 1 to 26 do
  34.         for j := 1 to 26 do
  35.             if cnt[i][j] > cnt[itf][its] then
  36.             begin
  37.                 itf := i;
  38.                 its := j;
  39.             end;
  40.    
  41.     writeln(chr(itf + ord('a') - 1), ' ', chr(its + ord('a') - 1));
  42. end.
Advertisement
Add Comment
Please, Sign In to add comment