-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUnit3.pas
123 lines (102 loc) · 2.99 KB
/
Unit3.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
unit Unit3;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm3 = class(TForm)
Label1: TLabel;
Edit1: TEdit;
Button1: TButton;
Label2: TLabel;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form3: TForm3;
implementation
{$R *.dfm}
Const
probel:set of char = [' '];
big: set of char = ['À'..'Å' , '¨','Æ'..'ß'];
BukvKir: set of char = ['À'..'Å' , '¨','Æ'..'ß' ,'à'..'ÿ' , '¸' ];
small: set of char = ['à'..'ÿ','¸'];
BukvLat: set of char = ['A'..'Z','a'..'z'];
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 Probel) or (S[i] in BukvKir) 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
len:=length(s);
Z:=1;
Repeat
flag:=true;
for i:=1 to (len-Z) do
if (s[i] in probel) and ((s[i+1] in BukvKir) or (s[i+1] in BukvLat)) or
((s[i] in BukvLat) and (s[i+1] in BukvKir)) or
(s[i] in small) and (s[i+1]in big) and (s[i]='¸') or
(s[i] in small) and (s[i+1]in big) and (ansiuppercase(s[i])=s[i+1]) or
(s[i]in BukvKir) and (s[i+1] in BukvKir) and ((s[i+1]='¨') and (ansiuppercase(s[i])>'Å') or
(s[i]in BukvKir) and (s[i+1] in BukvKir) and (ansiuppercase(s[i+1])<'Æ') and ((s[i]='¨')) or
(s[i]in BukvKir) and (s[i+1] in BukvKir) and (ansiuppercase(s[i+1])<ansiuppercase(s[i])) and (ansiuppercase(s[i+1])>'¨' ) or
(s[i]in BukvKir) and (s[i+1] in BukvKir) and (s[i+1]='¸') and (ansiuppercase(s[i])>'Å') or
(s[i]in BukvKir) and (s[i+1] in BukvKir) and (s[i]='¸') and (s[i+1]='¨') or
(s[i]in BukvKir) and (s[i+1] in BukvKir) and (ansiuppercase(s[i+1])<'Æ') and ((s[i]='¸')) or
(s[i]in BukvKir) and (s[i+1] in BukvKir) and (ansiuppercase(s[i+1])<ansiuppercase(s[i])) and ((s[i+1])>'å') )
then
begin
ch:=s[i]; s[i]:=s[i+1]; s[i+1]:=ch; flag:= false;
if (s[i]='¸') and ( s[i+1]='¨') then begin
ch:=s[i];
s[i]:=s[i+1];
s[i+1]:=ch;
end;
end;
INC(Z)
Until flag;
End;
procedure TForm3.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; {case}
procedure TForm3.Button2Click(Sender: TObject);
begin
close;
end;
end.