Составить программу нахождения согласной,чаще всего встречающейся в слове — Pascal(Паскаль)

const
 sgl = ['q','w','r','t','y','p','s','d','f','g','h','k','l','z','x','c','v','b','n','m'];
var
 s:string;
 i,j,max,max2,count: integer;
begin
 readln(s);
 for i:= 1 to length(s) do begin
   if count > max then begin
     max:= count;
     max2:= i-1;
   end;
   count:= 0;
   for j:= i+1 to length(s) do begin
     if (s[i] = s[j]) and (s[i] in sgl) then
     inc(count);
   end;
 end;
 if (max2 >= 1) and (max2 <= length(s)) then
 writeln(s[max2]);
end.

Вариант 2

const sgl='qwrtypsdfghklzxcvbnmj';
var s:string;
     k,i,j,max:byte;
     c:char;
begin
readln(s);
max:=0;
for i:=1 to length(sgl) do
 begin
  k:=0;
  for j:=1 to length(s) do
  if s[j]=sgl[i] then inc(k);
  if k>max then
   begin
    max:=k;
    c:=sgl[i];
   end;
 end;
write(c);
end.

Leave a Comment

49 − 48 =