Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program Lab3_2;
- uses
- System.SysUtils;
- type
- CharArray = array of Char;
- function GetInputType(): String;
- var
- Ret: string;
- IsCorrect: Boolean;
- begin
- IsCorrect := False;
- repeat
- Writeln('Выберите способ ввода предложения файл/консоль (ф/к)');
- Readln(Ret);
- if (Ret = 'ф') or (Ret = 'Ф') or (Ret = 'Файл') or (Ret = 'файл') then
- begin
- Ret := 'File';
- IsCorrect := True;
- end
- else if (Ret = 'к') or (Ret = 'К') or (Ret = 'Консоль') or
- (Ret = 'консоль') then
- begin
- Ret := 'Console';
- IsCorrect := True;
- end;
- until IsCorrect;
- GetInputType := Ret;
- end;
- function GetInputFilePath(): String;
- var
- Path: String;
- IsCorrect: Boolean;
- begin
- IsCorrect := False;
- repeat
- Writeln('Введите абсолютный путь к файлу ');
- Readln(Path);
- if FileExists(Path) then
- IsCorrect := True
- else
- Writeln('Файл не найден');
- until IsCorrect;
- GetInputFilePath := Path;
- end;
- function GetInputTextFromConsole(): String;
- var
- Ret: String;
- begin
- Writeln('Введите исходное предложение');
- Readln(Ret);
- GetInputTextFromConsole := Ret;
- end;
- function GetInputTextFromFile(): String;
- var
- Ret, Temp, FilePath: String;
- InputFile: TextFile;
- begin
- FilePath := GetInputFilePath();
- AssignFile(InputFile, FilePath);
- Reset(InputFile);
- while not Eof(InputFile) do
- begin
- Readln(InputFile, Temp);
- Ret := Ret + Temp;
- end;
- CloseFile(InputFile);
- GetInputTextFromFile := Ret;
- end;
- function GetInputString(): String;
- var
- Ret, InputType: String;
- begin
- InputType := GetInputType();
- if (InputType = 'Console') then
- Ret := GetInputTextFromConsole()
- else if (InputType = 'File') then
- Ret := GetInputTextFromFile();
- GetInputString := Ret;
- end;
- Function GetEntryCount(Input: String; Symbol: Char):Byte;
- var
- I, Count: Byte;
- begin
- Count := 0;
- for I := 1 to Input.Length do
- if Input[I] = Symbol then
- inc(Count);
- GetEntryCount := Count;
- end;
- function GetVowels(InputText: String): CharArray;
- var
- Ret: CharArray;
- Vowels: Set of Char;
- I, Count: Integer;
- begin
- Vowels := ['e', 'y', 'u', 'i', 'o', 'a'];
- Count := 0;
- Setlength(Ret, 6);
- InputText := LowerCase(InputText);
- for I := 1 to InputText.Length do
- begin
- if (InputText[I]in Vowels) and (GetEntryCount(InputText,InputText[I]) = 1) then
- begin
- Ret[Count] := InputText[I];
- inc(Count);
- end;
- end;
- Setlength(Ret, Count);
- GetVowels := Ret;
- end;
- function SortArray(UnSortedArray: CharArray): CharArray;
- var
- I, J, Size: Integer;
- Temp: Char;
- begin
- Size := High(UnSortedArray) - 1;
- for I := 0 to Size do
- for J := 0 to Size do
- if UnSortedArray[J] > UnSortedArray[J + 1] then
- begin
- Temp := UnSortedArray[J + 1];
- UnSortedArray[J + 1] := UnSortedArray[J];
- UnSortedArray[J] := Temp;
- end;
- SortArray := UnSortedArray;
- end;
- function GetSortedVowels(InputText: String): CharArray;
- var
- Vowels: CharArray;
- begin
- Vowels := GetVowels(InputText);
- Vowels := SortArray(Vowels);
- GetSortedVowels := Vowels;
- end;
- function GetOutputDirectory(): String;
- var
- Ret: String;
- IsCorrect: Boolean;
- begin
- IsCorrect := False;
- repeat
- Writeln('Введите директорию, в которую хотите сохранить вывод программы');
- Readln(Ret);
- if DirectoryExists(Ret) then
- IsCorrect := True
- else
- Writeln('Такой директории не существует.Попробуйте ещё раз');
- until IsCorrect;
- GetOutputDirectory := Ret;
- end;
- procedure PrintOutputToFile(ToPrint: CharArray);
- var
- OutputFile: TextFile;
- I: Integer;
- Directory: String;
- begin
- Directory := GetOutputDirectory();
- AssignFile(OutputFile, Directory + '\output.txt');
- Rewrite(OutputFile);
- Writeln(OutputFile, 'Глассные буквы, которые входят только в одно слово: ');
- for I := 0 to High(ToPrint) do
- Write(OutputFile, ToPrint[I] + ' ');
- Writeln('Файл сохранён по указанному пути');
- CloseFile(OutputFile);
- end;
- procedure PrintOutputToConsole(ToPrint: CharArray);
- var
- I: Integer;
- begin
- Writeln('Глассные буквы, которые входят только в одно слово: ');
- for I := 0 to High(ToPrint) do
- Write(ToPrint[I] + ' ');
- Writeln;
- end;
- Var
- InputString: String;
- Output: CharArray;
- begin
- InputString := GetInputString();
- Output := GetSortedVowels(InputString);
- PrintOutputToConsole(Output);
- PrintOutputToFile(Output);
- Readln;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement