Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Program AiSD_1_3;
- {$APPTYPE CONSOLE}
- {$R *.res}
- Uses
- System.SysUtils;
- Type
- TString = String[20];
- User = ^TUser;
- TUser = Record
- UserName: TString;
- PhoneNumber: Integer;
- Next: User;
- End;
- Function InputList(Count: Integer): User;
- Var
- Element, Head, Start: User;
- I: Integer;
- IsCorrect: Boolean;
- Temp: String;
- LowerTemp: String[20];
- Begin
- New(Element);
- Head := Element;
- Start := Element;
- I := 0;
- While I < Count Do
- Begin
- IsCorrect := True;
- Start := Head;
- Writeln('Абонент №', I + 1, ':');
- Repeat
- Readln(Element^.UserName);
- Until Length(Element^.UserName) < 21;
- Element^.UserName[1] := UpCase(Element^.UserName[1]);
- LowerTemp := Copy(Element^.UserName, 2, Length(Element^.UserName));
- Delete(Element^.UserName, 2, Length(Element^.UserName));
- Element^.UserName := Element^.UserName + LowerCase(LowerTemp);
- Writeln('Номер телефона: ', I + 1);
- Repeat
- IsCorrect := True;
- Try
- Readln(Temp);
- Element^.PhoneNumber := StrToInt(Temp);
- Except
- IsCorrect := False;
- Writeln('Проверьте корректность данных!');
- End;
- If IsCorrect And (Length(Temp) <> 7) Then
- Begin
- IsCorrect := False;
- Writeln('Введите семизначное число!');
- End;
- Until IsCorrect;
- While (Start^.Next <> Element^.Next) And IsCorrect Do
- Begin
- If (Start^.UserName = Element^.UserName) And
- (Start^.PhoneNumber = Element^.PhoneNumber) Then
- IsCorrect := False;
- Start := Start^.Next;
- End;
- If IsCorrect Then
- Begin
- New(Element^.Next);
- Element := Element^.Next;
- Inc(I);
- End
- Else
- Writeln('Проверьте корректность данных!');
- End;
- Element^.Next := Nil;
- Result := Head;
- End;
- Procedure SortList(Count: User);
- Var
- Temp, Start: User;
- TempSwap: String[20];
- PhoneSwap: Integer;
- Begin
- Start := Count;
- While Start^.Next <> Nil Do
- Begin
- Temp := Start^.Next;
- While Temp^.Next <> Nil Do
- Begin
- If Temp^.UserName < Start^.UserName Then
- Begin
- TempSwap := Temp^.UserName;
- Temp^.UserName := Start^.UserName;
- Start^.UserName := TempSwap;
- PhoneSwap := Temp^.PhoneNumber;
- Temp^.PhoneNumber := Start^.PhoneNumber;
- Start^.PhoneNumber := PhoneSwap;
- End;
- Temp := Temp^.Next;
- End;
- Start := Start^.Next;
- End;
- End;
- Procedure OutputList(Count: User);
- Var
- Start: User;
- Begin
- Start := Count;
- While Start^.Next <> Nil Do
- Begin
- Write(Start^.UserName + '–' + IntToStr(Start^.PhoneNumber), #13#10);
- Start := Start^.Next;
- End;
- End;
- Procedure FindFromNumber(Count: User);
- Var
- Start: User;
- Temp: String;
- TempInt: Integer;
- IsCorrect: Boolean;
- Begin
- Repeat
- IsCorrect := True;
- Try
- Readln(Temp);
- TempInt := StrToInt(Temp);
- Except
- IsCorrect := False;
- Writeln('Проверьте корректность данных!');
- End;
- If IsCorrect And (Length(Temp) <> 7) Then
- Begin
- IsCorrect := False;
- Writeln('Введите семизначное число!');
- End;
- Until IsCorrect;
- Start := Count;
- While Start^.Next <> Nil Do
- Begin
- If (Start^.PhoneNumber = TempInt) Then
- Writeln(Start^.UserName);
- Start := Start^.Next;
- End;
- End;
- Procedure FindFromUserName(Count: User);
- Var
- Start: User;
- Temp: TString;
- Begin
- Writeln('Введите имя абонента:');
- Repeat
- Readln(Temp);
- Until Length(Temp) < 21;
- Start := Count;
- While Start^.Next <> Nil Do
- Begin
- If (Start^.UserName = Temp) Then
- Writeln(Start^.PhoneNumber);
- Start := Start^.Next;
- End;
- End;
- Function InputChoice(): String;
- Var
- Str: String;
- IsCorrect: Boolean;
- Numb: Integer;
- Begin
- Repeat
- IsCorrect := True;
- Try
- Readln(Str);
- Numb := StrToInt(Str);
- Except
- IsCorrect := False;
- Writeln('Повторите ввод!');
- End;
- If IsCorrect And ((Numb > 3) Or (Numb < 1)) Then
- Until IsCorrect;
- Result := Str;
- End;
- //Main
- Var
- IsIncorrect: Boolean;
- Count: Integer;
- Head: User;
- Number: Integer;
- Str: TString;
- Begin
- Write('Введите количество абонентов (от 2 до 6): ');
- Repeat
- IsInCorrect := True;
- Try
- Readln(Count);
- Except
- IsInCorrect := False;
- Writeln('Проверьте корректность данных!');
- End;
- If IsIncorrect And ((Count > 6) Or (Count < 2)) Then
- Begin
- IsIncorrect := False;
- Writeln('Проверьте корректность данных!');
- End;
- Until IsIncorrect;
- Head := InputList(Count);
- SortList(Head);
- OutputList(Head);
- Repeat
- Writeln('Нажмите', #13#10, '1 для поиска фамилии по номеру телефона', #13#10, '2 для поиска телефона по фамилии', #13#10, '3 чтобы выйти');
- Str := InputChoice();
- If Str = '1' Then
- FindFromNumber(Head)
- Else If Str = '2' Then
- FindFromUserName(Head);
- Until StrToInt(Str) = 3;
- End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement