Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Unit1;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls, Menus;
- type
- TForm1 = class(TForm)
- GroupBox1: TGroupBox;
- mm_Out: TMemo;
- mm_In: TMemo;
- MainMenu1: TMainMenu;
- N1: TMenuItem;
- N2: TMenuItem;
- N3: TMenuItem;
- N4: TMenuItem;
- Label1: TLabel;
- Label2: TLabel;
- N5: TMenuItem;
- procedure N2Click(Sender: TObject);
- procedure N3Click(Sender: TObject);
- procedure N4Click(Sender: TObject);
- procedure N5Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- Form1: TForm1;
- FIn, FOut : TextFile;
- implementation
- {$R *.dfm}
- procedure TForm1.N2Click(Sender: TObject);
- const
- WordMax = 30;
- type
- StringList = array[1..WordMax] of String;
- var
- HandlingText, OutString : String;
- DiffWords : StringList;
- I, Count : Integer;
- procedure SplitText(Text : String; var Mass : StringList; var N : Integer);
- var
- DiffWords : StringList;
- TempText, Word : String;
- Position, Len: Integer;
- begin
- TempText := Text;
- Position := Pos(' ', TempText);
- N := 1;
- while Len > 0 do
- begin
- if Position = 0 then
- begin
- Word := TempText;
- TempText := '';
- end
- else
- begin
- Word := Copy(TempText, 1, Position - 1);
- TempText := Copy(TempText, Position + 1, Length(TempText) - Position);
- end;
- if Length(Word) > 10 then
- ShowMessage('Максимальная длина слова -- 10. Слово"' + Word + '" Будет проигнорировано.')
- else
- begin
- Mass[N] := Word;
- N := N + 1;
- end;
- Len := Length(TempText);
- Position := Pos(' ', TempText);
- if N > 30 then
- begin
- Len := 0;
- ShowMessage('Максимальное количество слов -- 30. Слова, следующие за 30-м будут проигнорированы.');
- end;
- end;
- N := N - 1;
- end;
- procedure HandleText(Text : String; var DiffWords : StringList; var J : Integer);
- var
- Words : StringList;
- LastWord,x : String;
- Count, I, K, Sum : Integer;
- begin
- Text := StringReplace(Text, ' ', ' ', [rfReplaceAll]);
- SplitText(Text, Words, Count);
- LastWord := StringReplace(Words[Count], '.', '', [rfReplaceAll]);
- J := 1;
- for I := 1 to Count - 1 do
- if Words[I] <> LastWord then
- begin
- Sum := 0;
- for K := 1 to Length(Words[I]) do
- begin
- if Words[I][K] in ['0'..'9'] then
- Sum := Sum + StrToInt(Words[I][K]);
- end;
- if Sum <> 0 then Words[I] := Words[I] + IntToStr(Sum);
- if Length(Words[I]) > 0 then
- begin
- DiffWords[J] := Words[I];
- J := J + 1;
- end;
- end;
- J := J - 1;
- end;
- begin
- Reset(FIn);
- Read(FIn, HandlingText);
- CloseFile(FIn);
- mm_In.Text := HandlingText;
- HandleText(HandlingText, DiffWords, Count);
- OutString := '';
- for I := 1 to Count do
- OutString := Concat(OutString, DiffWords[I], ' ');
- mm_Out.Text := OutString;
- Rewrite(FOut);
- Write(FOut, OutString);
- CloseFile(FOut);
- end;
- procedure TForm1.N3Click(Sender: TObject);
- begin
- mm_In.Text := '';
- mm_Out.Text := '';
- end;
- procedure TForm1.N4Click(Sender: TObject);
- begin
- Close;
- end;
- procedure TForm1.N5Click(Sender: TObject);
- begin
- mm_in.Lines.SaveToFile('InFile.txt'); //Сохраняем входной текст в файл
- end;
- initialization
- AssignFile(FIn, 'InFile.txt'); //Инициализируем входной файл
- AssignFile(FOut, 'OutFile.txt'); //Инициализируем выходной файл
- Finalization
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement