How to find missing alphabet characters from a string in Pascal

1 Answer

0 votes
program MissingAlphabet;

type
  TStringArray = array[1..26] of char;

procedure GetMissingAlphabetChars(Input: string; var Missing: TStringArray; var Count: Integer);
var
  Present: set of char;
  C: char;
  I: Integer;
begin
  Present := [];

  { Normalize input: lowercase + keep only a..z }
  for I := 1 to Length(Input) do
  begin
    C := Input[I];
    if (C >= 'A') and (C <= 'Z') then
      C := Chr(Ord(C) + 32);  { convert to lowercase }

    if (C >= 'a') and (C <= 'z') then
      Include(Present, C);
  end;

  { Collect missing letters }
  Count := 0;
  for C := 'a' to 'z' do
    if not (C in Present) then
    begin
      Inc(Count);
      Missing[Count] := C;
    end;
end;

var
  Missing: TStringArray;
  Count, I: Integer;

begin
  GetMissingAlphabetChars('PHP Programming', Missing, Count);

  for I := 1 to Count do
    WriteLn(Missing[I]);
end.





(*
run:

b
c
d
e
f
j
k
l
q
s
t
u
v
w
x
y
z

*)

 



answered Mar 6 by avibootz
...