Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Unit1;
- {$mode objfpc}{$H+}
- interface
- uses
- Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;
- type
- { TForm1 }
- TForm1 = class(TForm)
- Button1: TButton;
- Memo1: TMemo;
- Memo2: TMemo;
- procedure Button1Click(Sender: TObject);
- private
- { private declarations }
- public
- { public declarations }
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.lfm}
- { TForm1 }
- const
- MAXN = 10000;
- type
- TSym = record
- a :integer;
- p :integer;
- end;
- Tmas = array[1 .. MAXN] of TSym;
- procedure swap(var a, b :TSym);
- var
- c :integer;
- begin
- c:= a.a;
- a.a:= b.a;
- b.a:= c;
- end;
- procedure qSort(var v :Tmas; l,r :longint);
- var i,j:longint;
- q :integer;
- begin
- i := l; j := r;
- q := v[(l+r) div 2].a;
- repeat
- while (v[i].a < q) do inc(i);
- while (q < v[j].a) do dec(j);
- if (i <= j) then
- begin
- swap(v[i], v[j]);
- inc(i); dec(j);
- end;
- until (i > j);
- if (l < j) then qSort(v, l,j);
- if (i < r) then qSort(v, i,r);
- end;
- function work(s :string) :string;
- var
- n, i :integer;
- arr :Tmas;
- begin
- n:= 0;
- for i:= 1 to length(s) do
- if(pos(s[i], '0123456789') <> 0) then
- begin
- inc(n);
- arr[n].a:= pos(s[i], '0123456789') - 1;
- arr[n].p:= i;
- end;
- if(n <> 0) then
- qSort(arr, 1, n);
- for i:= 1 to n do
- begin
- delete(s, arr[i].p, 1);
- insert(inttostr(arr[i].a), s, arr[i].p);
- end;
- work:= s;
- end;
- procedure TForm1.Button1Click(Sender: TObject);
- begin
- Memo2.append(work(Memo1.Lines[0]));
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement