Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program Project2;
- {$APPTYPE CONSOLE}
- {$R *.res}
- uses
- System.SysUtils;
- const
- Amount = 5;
- ErrorMessage = 'Error! Enter name (nonempty string, starts with uppercase letter)';
- function IsName(Name: string) : Boolean;
- var
- NameLength, i : Integer;
- HasSuchLetter : Boolean;
- Alphabet : set of 'a'..'z';
- begin
- Alphabet := ['a'..'z'];
- NameLength := Length(Name);
- IsName := True;
- if Name <> '' then
- if Name[1] <> LowerCase(Name[1]) then
- for i := 2 to NameLength do
- if not (Name[i] in Alphabet) then
- IsName := False
- else
- IsName := False
- else
- IsName := False;
- end;
- var
- MyName : string;
- i, Counter, Index : Integer;
- HasStarted, IsInvalid : Boolean;
- List: array [0 .. 4] of string = ('Artem', 'Maxim', 'Arseniy', 'Vasya', 'Merlin');
- begin
- HasStarted := False;
- IsInvalid := True;
- Writeln('This program can recognize and greet one of 5 friends');
- repeat
- Counter := 0;
- Index := -1;
- while IsInvalid do
- try
- if not HasStarted then
- Writeln('Enter name:')
- else
- Writeln('Please, clarify the name:');
- Readln(MyName);
- if (MyName = '') or (MyName[1] = LowerCase(MyName[1])) then
- Writeln(ErrorMessage)
- else
- IsInvalid := False;
- except
- Writeln(ErrorMessage);
- end;
- IsInvalid := True;
- for i := 0 to Amount - 1 do
- if Pos(MyName, List[i]) = 1 then
- begin
- Counter := Counter + 1;
- Index := i;
- end;
- Writeln('Matches found: ', Counter);
- if Counter = 0 then
- Counter := 1;
- HasStarted := True;
- until Counter = 1;
- if Index = -1 then
- Writeln('I DON''T KNOW YOU!')
- else
- Writeln(List[Index], ', nice to meet you!');
- Readln;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement