-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUnit1.pas
104 lines (92 loc) · 2.39 KB
/
Unit1.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
Label2: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
Const
BukvKirSTR: set of char = ['�'..'�','�','�'..'�','�'..'�','�'];
BukvLat: set of char =['A'..'Z','a'..'z'];
BukvLatm: set of char = ['a'..'z'];
Prob: set of char = [' '];
BukvLatb: set of char = ['A'..'Z'];
var
Form1: TForm1;
implementation
{$R *.dfm}
Function Prov(const s: string): byte;
Var
Nom: byte; // ����� ��������
i,Len: word; // ������� ������ � ����� ������
Begin
Nom:=0; len:= Length(S);
If Len=0 then Nom:=1
Else
Begin
i:=1;
while (i<=Len) and (Nom=0) do
begin
if Not ((S[i] in Prob) or (S[i] in BukvKirSTR) or (S[i] in BukvLat)) then Nom:=2;
Inc(i);
end;
End;
Prov:=Nom;
End;
Procedure Sort(var s:string);
Var
i, z, len: Word; // ����� �������� �������, ����� �������� (����), ����� ������
flag: Boolean; // �����������? (��� �������?)
ch: char; // ��� ������
Begin
Z:=1; len:=length(s);
Repeat
flag:=true;
for i:=1 to len-z do
if (s[i] in BukvLat) and ((s[i+1] in BukvKirSTR) or
(s[i+1] in Prob)) or (s[i] in BukvKirSTR)
and (s[i+1] in Prob) or
(s[i] in BukvLat) and (s[i+1] in BukvLat)
and (ansiuppercase(s[i])>ansiuppercase(s[i+1]))
or (s[i] in BukvLatm) and (s[i+1] in BukvLatb) and (ansiuppercase(s[i])=s[i+1])
then
begin // �����
ch:=s[i]; s[i]:=s[i+1]; s[i+1]:=ch; flag:= false;
end;
inc(z);
Until flag or (z=len);
End;
procedure TForm1.Button1Click(Sender: TObject);
var
s: string; Nom: byte;
begin
s:=Edit1.Text; // ���� ������ S
// ��������
Nom:= Prov(s);
Case Nom of
1: Label2.Caption := '������ ������';
2: Label2.Caption := '������������ �������';
else
begin // ����������
Sort(s);
Label2.Caption:='"'+s+'"'; // ����� ������ S
end; {else}
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
form1.Close;
end;
end.