Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Program b3_3;
- Uses
- System.SysUtils, Classes;
- type
- InputType = (FromConsole, FromFile);
- ListD = record
- Name:AnsiString;
- Score:Integer;
- end;
- Aos = Array of ListD;
- Var
- Path: String;
- Sentence: String;
- Size: Integer;
- List: Aos;
- function GetInputType(): InputType;
- var
- Ret: InputType;
- Input: String;
- IsCorrect: Boolean;
- begin
- IsCorrect := False;
- repeat
- Writeln('Выберите способ ввода предложения файл/консоль (ф/к)');
- Readln(Input);
- if (Input = 'ф') or (Input = 'Ф') or (Input = 'Файл')
- or (Input = 'файл')
- then
- begin
- Ret := InputType.FromFile;
- IsCorrect := True;
- end
- else if (Input = 'к') or (Input = 'К') or (Input =
- 'Консоль') or (Input = 'консоль') then
- begin
- Ret := InputType.FromConsole;
- IsCorrect := True;
- end;
- until IsCorrect;
- Result := Ret;
- end;
- function IntSize(Size: Integer): Integer;
- var
- IsCorrect: Boolean;
- Begin
- Writeln('Введите количество участников: ');
- repeat
- IsCorrect := True;
- try
- Readln(Size);
- except
- Writeln('Введите целое число!');
- IsCorrect := False;
- end;
- if Size <= 0 then
- begin
- Writeln('Введите положительное число!');
- IsCorrect := False
- end;
- until (IsCorrect);
- IntSize := Size;
- End;
- function GetSentenceFromConsole(List: Aos; Size: Integer): Aos;
- var
- I, J, Ind, bif: Integer;
- IsCorrect: Boolean;
- Buf: AnsiString;
- bfs: String;
- begin
- SetLength(List, Size);
- for I := 0 to Size-1 do
- begin
- repeat
- IsCorrect := True;
- Writeln('Введите фамилию участника');
- Readln(List[I].Name);
- List[I].Name := Trim(List[I].Name);
- Buf := List[I].Name;
- for J := 1 to Length(Buf) do
- begin
- if (NOT(Buf[J] in ['А'..'Я' , 'а'..'я'])) then
- begin
- IsCorrect := False;
- end;
- end;
- if IsCorrect = false then
- begin
- Writeln('Фамилия должна состоять из русских букв')
- end;
- until (IsCorrect);
- repeat
- Writeln('Введите счёт игрока');
- IsCorrect := True;
- try
- Readln(List[I].Score);
- except
- Writeln('Введите целое число!');
- IsCorrect := False;
- end;
- if List[I].Score < 0 then
- begin
- Writeln('Введите неотрицательное число!');
- IsCorrect := False
- end;
- until (IsCorrect)
- end;
- writeln;
- for J := i + 1 to Size do
- if List[I].Score < List[J].Score then
- begin
- bif := List[J].Score;
- List[J].Score := List[I].Score;
- List[I].Score := bif;
- bfs := List[I].Name;
- List[I].Name := List[J].Name;
- List[J].Name := bfs;
- end;
- {for I := 0 to size-1 do
- begin
- Writeln(List[I].Name, ' ', List[I].Score)
- end;}
- Writeln(List[0].Name, ' ', List[0].Score);
- for I := 0 to Size-1 do
- begin
- if ((List[I].Score = List[0].Score) and (List[I].Name <> List[0].Name)) then
- begin
- Writeln(List[I].Name, ' ', List[I].Score);
- Ind := I;
- end;
- end;
- writeln('indone=', ind);
- for I := Ind to Size-1 do
- begin
- if ((List[I].Score = List[I+1].Score) and (List[I].Name <> List[I+1].Name)) then
- begin
- Writeln(List[I].Name, ' ', List[I].Score);
- Ind := I;
- end;
- end;
- writeln('indtwo=', ind);
- for I := Ind to Size-1 do
- begin
- if ((List[I].Score = List[I+1].Score) and (List[I].Name <> List[I+1].Name)) then
- begin
- Writeln(List[I].Name, ' ', List[I].Score)
- end;
- end;
- end;
- Function GetFilePath(): String;
- Var
- Path: String;
- IsCorrect: Boolean;
- Begin
- Repeat
- Writeln('Введите абсолютный путь к файлу ');
- Readln(Path);
- IsCorrect := False;
- If FileExists(Path) then
- Begin
- Writeln('Файл успешно открыт');
- IsCorrect := true
- End
- Else
- Writeln('Файл не найден');
- Until IsCorrect;
- GetFilePath := Path;
- End;
- Function GetSentenceFromFile(Sentence:String): String;
- Var
- SenFile: TextFile;
- Begin
- Path := GetFilePath();
- AssignFile(SenFile, Path);
- Reset(SenFile);
- Read(SenFile, Sentence);
- CloseFile(SenFile);
- GetSentenceFromFile := Sentence;
- End;
- Procedure PrintSentenceBeforeEditing(Sentence: String);
- Begin
- Writeln;
- Writeln('Исходное предложение: ');
- Write(Sentence);
- Writeln;
- End;
- function GetSentence():Aos;
- var
- SelectedInputType: InputType;
- begin
- SelectedInputType := GetInputType();
- if (SelectedInputType = InputType.FromConsole) then
- begin
- List := GetSentenceFromConsole(List, Size)
- end
- else if (SelectedInputType = InputType.FromFile) then
- begin
- Sentence := GetSentenceFromFile(Sentence);
- end;
- PrintSentenceBeforeEditing(Sentence);
- GetSentence := List;
- end;
- Function Output(): String;
- Var
- Patho: String;
- IsCorrect: Boolean;
- Begin
- IsCorrect := False;
- Repeat
- Writeln('Введите директорию, в которую хотите сохранить результат');
- Readln(Patho);
- If DirectoryExists(Patho) then
- IsCorrect := True
- Else
- Writeln('Такой директории не существует. Попробуйте ещё раз');
- Until IsCorrect;
- Output := Patho;
- End;
- Procedure SaveSentenceToFile(Sentence: String);
- Var
- I, J: Integer;
- OutputFile: TextFile;
- Directory: String;
- Begin
- Directory := Output();
- AssignFile(OutputFile, Directory + '\output.txt');
- Rewrite(OutputFile);
- Write(OutputFile,Sentence);
- Writeln(OutputFile);
- Writeln('Результат сохранён по указанному пути');
- CloseFile(OutputFile);
- Write;
- End;
- Procedure PrintSentenceAfterEditing(var Sentence: String);
- Begin
- Writeln;
- if Length(Sentence) < 1 then
- Sentence := 'Ни один символ не прошёл проверку! От вашей строки ничего не осталось!'
- else
- Writeln('Исправленное предложение:');
- Writeln(Sentence);
- Writeln;
- End;
- Function Edit(Sentence: String): String;
- Var
- I:Integer;
- Begin
- I := 1;
- while (I <= Length(Sentence)) do
- begin
- if (NOT(Sentence[I] in ['0'..'9', 'a'..'z' , 'A'..'Z', ' '])) then
- begin
- Delete(Sentence, I, 1);
- Dec(I);
- end;
- Inc(I)
- end;
- Edit := Sentence;
- End;
- Begin
- Size := IntSize(Size);
- List := GetSentence();
- Sentence := Edit(Sentence);
- PrintSentenceAfterEditing(Sentence);
- SaveSentenceToFile(Sentence);
- Readln;
- End.
Add Comment
Please, Sign In to add comment