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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
| unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, ExtCtrls, ComCtrls, Menus, ExtDlgs;
type
TForm1 = class(TForm)
Image1: TImage;
Button3: TButton;
StringGrid2: TStringGrid;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
Button2: TButton;
Button1: TButton;
StringGrid1: TStringGrid;
Button4: TButton;
Button5: TButton;
StringGrid3: TStringGrid;
Edit1: TEdit;
Label1: TLabel;
Button6: TButton;
Label2: TLabel;
Edit2: TEdit;
Edit3: TEdit;
Label3: TLabel;
Button7: TButton;
Button9: TButton;
Button8: TButton;
Button10: TButton;
MainMenu1: TMainMenu;
N1: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
N5: TMenuItem;
N6: TMenuItem;
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
N4: TMenuItem;
TrackBar1: TTrackBar;
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure redrow;
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Button9Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button10Click(Sender: TObject);
procedure N5Click(Sender: TObject);
procedure N2Click(Sender: TObject);
procedure N3Click(Sender: TObject);
procedure N6Click(Sender: TObject);
procedure N4Click(Sender: TObject);
procedure TrackBar1Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
vv = record
x,y:Integer;
num:Integer;
end;
gph= array[1..99,1..99] of byte;
var
Form1: TForm1;
pos,pos2:Integer;
xx,yy,xb,yb,ugol:Integer;
ver,reb,reb2:Boolean;
vers:array[1..100] of vv;
implementation
uses Math, Unit2;
{$R *.dfm}
function findver(x,y:integer):Integer;
var i:Integer;
begin
findver:=0;
for i:=1 to pos do begin
if (x>vers[i].x-10) and (x<vers[i].x+10) and (y>vers[i].y-10) and (y<vers[i].y+10) then
findver:=i;
end;
end;
procedure TForm1.redrow;
var i,i2:Integer;
begin
Image1.Canvas.Pen.Mode := pmCopy;
Image1.Canvas.Brush.Color := clWhite;
Image1.Canvas.Rectangle(0,0,Image1.Width,Image1.Height);
for i:=1 to pos2 do begin
i2:=strtoint(StringGrid1.Cells[i,0]);
Image1.Canvas.MoveTo(vers[i2].x,vers[i2].y);
i2:=strtoint(StringGrid1.Cells[i,1]);
Image1.Canvas.lineTo(vers[i2].x,vers[i2].y);
end;
for i:=1 to pos do begin
Image1.Canvas.Ellipse(vers[i].x-10,vers[i].y-10,vers[i].x+10,vers[i].y+10);
Image1.Canvas.TextOut(vers[i].x-3,vers[i].y-6,inttostr(i));
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
pos:=0;
pos2:=0;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
reb:=false;
xx:=-100;
yy:=-100;
Image1.Canvas.Pen.Mode := pmNotXor;
ver:= True;
end;
procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if ver then begin
Image1.Canvas.Ellipse(xx-10,yy-10,xx+10,yy+10);
xx:x;
yy:=y;
Image1.Canvas.Ellipse(x-10,y-10,x+10,y+10);
end;
if reb2 then begin
Image1.Canvas.MoveTo(xb,yb);
Image1.Canvas.LineTo(xx,yy);
xx:x;
yy:=y;
Image1.Canvas.MoveTo(xb,yb);
Image1.Canvas.LineTo(x,y);
end else begin
xb:x;
yb:=y;
end;
end;
procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var i,i2,xx,yy:integer;
begin
If ver then begin
inc(pos);
vers[pos].x:x;
vers[pos].y:=y;
xx:=-100;yy:=-100;
vers[pos].num:=pos;
redrow;
ver:=FAlse;
Button2.Caption:= 'Разместить вершину '+IntToStr(pos+1);
If pos>1 then begin
StringGrid3.ColCount:= StringGrid3.ColCount+1;
StringGrid3.RowCount:=StringGrid3.ColCount;
Edit1.Text := inttostr(pos);
end;
for i:=1 to strtoint(edit1.text)+1 do begin
StringGrid3.Cells[i,0]:= inttostr(i);
StringGrid3.Cells[0,i]:= inttostr(i);
end;
for i:=1 to strtoint(edit1.text) do begin
for i2:=1 to strtoint(edit1.text) do begin
if StringGrid3.Cells[i2,i]='' then
StringGrid3.cells[i2,i]:='0';
end;
end;
end;
if reb2 then begin
reb:=false;
reb2:=false;
xx:=0;
yy:=0;
//form1.Caption:=inttostr(findver(x,y));
i:=findver(x,y);
If i <>0 then begin
StringGrid1.Cells[pos2,1]:=inttostr(i);
xx:= StrToInt(StringGrid1.Cells[pos2,0]);
yy:= StrToInt(StringGrid1.Cells[pos2,1]);
StringGrid3.Cells[xx,yy]:='1';
StringGrid3.Cells[yy,xx]:='0';
StringGrid1.ColCount:= StringGrid1.ColCount+1;
end;
redrow;
end;
if reb then begin
xb:x;
yb:=y;
xx:x;
yy:=y;
reb2:=True;
Image1.Canvas.MoveTo(0,0);
Image1.Canvas.LineTo(x,y);
i:=findver(x,y);
If i <>0 then begin
inc(pos2);
StringGrid1.Cells[pos2,0]:=inttostr(i);
// Form1.Caption:= inttostr(pos2);
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
xx:=0;
yy:=0;
Image1.Canvas.Pen.Mode := pmNotXor;
reb:=true;
end;
procedure TForm1.Button3Click(Sender: TObject);
var v_n,v_t:byte;
mass1,mass2:array [1..100,1..2] of byte;
stek1,stek2:array [1..100] of byte;
num1,num2,i,i2,i_,j,k,m:integer;
el:Boolean;
begin
el:=true;
for i:=1 to pos do begin
k:=0;
for i2:=1 to pos2 do begin
if (StringGrid1.Cells[i2,0] = inttostr(i)) or (StringGrid1.Cells[i2,1] = inttostr(i)) then inc(k);
end;
if (k mod 2 <>0) then el:=false;
end;
if not el then Application.MessageBox('Данный граф не является Элеровым', '', MB_OK);
{---------vvod reber----------}
k:=pos2;
for i_:=1 to k do
begin
mass1[i_,1]:=strtoint(StringGrid1.Cells[i_,0]);
mass1[i_,2]:=strtoint(StringGrid1.Cells[i_,1]);
mass2[i_,1]:=mass1[i_,1];
mass2[i_,2]:=mass1[i_,2];
end;
{----------------main-----------------}
v_n:=mass1[1,1];
v_t:=mass1[1,2];
stek1[1]:=v_n;
stek1[2]:=v_t;
num1:=3;
num2:=1;
mass1[1,1]:=0;
mass1[1,2]:=0;
repeat
m:=0;
for i_:=2 to k do
begin
if mass1[i_,1]=v_t then
begin
if mass1[i_,2]=v_n then
begin
stek2[num2]:=v_n;
inc(num2);
v_n:=v_t;
end else
begin
stek1[num1]:=mass1[i_,2];
inc(num1);
v_t:=mass1[i_,2];
end;
mass1[i_,1]:=0;
mass1[i_,2]:=0;
// i_:=k;
// break;
m:=1;
end;
if mass1[i_,2]=v_t then
begin
if mass1[i_,1]=v_n then
begin
stek2[num2]:=v_n;
inc(num2);
v_n:=v_t;
end else
begin
stek1[num1]:=mass1[i_,1];
inc(num1);
v_t:=mass1[i_,1];
end;
mass1[i_,1]:=0;
mass1[i_,2]:=0;
// i_:=k;
// break;
m:=1;
end;
end;
if m=0 then
begin
dec(num1);
stek2[num2]:=stek1[num1];
stek1[num1]:=0;
v_n:=stek1[num1-1];
v_t:=stek1[num1-1];
inc(num2);
end;
until num2>k+1;
{---------vyvod spiska reber----------}
// for i_:=1 to k do write (mass2[i,1],' ');
// for i_:=1 to k do write (mass2[i,2],' ');
{---------vyvod vershin grafa----------}
StringGrid2.ColCount:=k;
for i_:=1 to k+1 do StringGrid2.Cells[i_-1,0]:= IntToStr(stek2[i_]);
// for i_:=1 to k+1 do write (stek2[i],' ');
end;
procedure TForm1.Button6Click(Sender: TObject);
var i,i2:Integer;
begin
If (Edit1.Text='') or (Edit1.Text='0') then Edit1.Text:='1';
StringGrid3.ColCount:=strtoint(edit1.text)+1;
StringGrid3.rowCount:=strtoint(edit1.text)+1;
for i:=1 to strtoint(edit1.text)+1 do begin
StringGrid3.Cells[i,0]:= inttostr(i);
StringGrid3.Cells[0,i]:= inttostr(i);
end;
for i:=1 to strtoint(edit1.text)+1 do begin
for i2:=1 to strtoint(edit1.text)+1 do begin
//StringGrid3.Cells[i,i2]:='0';
end;
end;
Button9.Click;
Button2.Caption:= 'Разместить вершину '+IntToStr(pos+1);
end;
procedure TForm1.Button7Click(Sender: TObject);
begin
StringGrid3.Cells[strtoint(Edit3.Text),strtoint(Edit2.Text)]:='1';
edit2.Text:='';
edit3.Text:='';
Edit2.SetFocus;
Button9.Click;
end;
procedure TForm1.Button9Click(Sender: TObject);
var i,i2:Integer;
step:real;
begin
pos2:=0;
for i:=1 to strtoint(edit1.text) do begin
for i2:=1 to strtoint(edit1.text) do begin
if StringGrid3.Cells[i2,i]='' then
StringGrid3.cells[i2,i]:='0';
if StringGrid3.Cells[i2,i]='1' then begin
Inc(pos2);
StringGrid1.ColCount:=pos2+1;
StringGrid1.Cells[pos2,0]:= inttostr(i);
StringGrid1.Cells[pos2,1]:= inttostr(i2);
StringGrid3.cells[i,i2]:='0';
end;
end;
end;
step:= 2*3.14/ strtoint(edit1.text);
for i:=1 to strtoint(edit1.text) do begin
vers[i].x := 300+ trunc(cos(i*step +ugol/100)*100);
vers[i].y := 150+ trunc(sin(i*step +ugol/100)*100);
pos:=i;
end;
redrow;
end;
procedure TForm1.Button8Click(Sender: TObject);
begin
StringGrid3.Cells[strtoint(Edit3.Text),strtoint(Edit2.Text)]:='0';
Button9.Click;
end;
procedure TForm1.Button5Click(Sender: TObject);
var x,y,pp:Integer;
begin
pos2:=pos2-1;
pp:= pos2+1;
x:= StrToInt(StringGrid1.Cells[pp,0]);
y:= StrToInt(StringGrid1.Cells[pp,1]);
StringGrid3.Cells[y,x]:='0';
StringGrid3.Cells[x,y]:='0';
if StringGrid1.ColCount<>1 then StringGrid1.ColCount:=StringGrid1.ColCount-1;
redrow;
//Image1.Canvas.Pen.Mode := pmCopy;
ver:= false;
reb := false;
reb2:=false;
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
pos:=pos-1;
StringGrid3.ColCount:= StringGrid3.ColCount-1;
StringGrid3.RowCount:= StringGrid3.ColCount;
edit1.Text := IntToStr(pos);
Button9.Click;
redrow;
Image1.Canvas.Pen.Mode := pmCopy;
ver:= false;
reb := false;
reb2:=false;
end;
procedure TForm1.Button10Click(Sender: TObject);
var i,i2:Integer;
begin
StringGrid1.ColCount:=2;
StringGrid1.Cells[1,0]:='';
StringGrid1.Cells[1,1]:='';
for i:=1 to strtoint(edit1.text)+1 do begin
for i2:=1 to strtoint(edit1.text)+1 do begin
StringGrid3.Cells[i,i2]:='0';
end;
end;
//Button9.Click;
end;
procedure TForm1.N5Click(Sender: TObject);
begin
Halt(0);
end;
procedure TForm1.N2Click(Sender: TObject);
var f:file;
pp,x,y:Byte;
mas:gph;
begin
If OpenDialog1.Execute then begin
assignFile(f,OpenDialog1.FileName);
Reset(f,1);
Blockread(f,pp,SIZEOF(byte));
Blockread(f,mas,SIZEOF(gph));
edit1.Text := IntToStr(pp);
CloseFile(F);
for x:=1 to pp do begin
for y:=1 to pp do begin
StringGrid3.Cells[x,y]:= inttostr(mas[x,y]);
end;
end;
Button6.Click
end;
end;
procedure TForm1.N3Click(Sender: TObject);
var f:file;
pp,x,y:Byte;
mas:gph;
begin
pp:=StrToInt(edit1.Text);
for x:=1 to pp do begin
for y:=1 to pp do begin
mas[x,y]:= strtoint(StringGrid3.Cells[x,y]);
end;
end;
If SaveDialog1.Execute then begin
assignFile(f,SaveDialog1.FileName);
Rewrite(f,1);
BlockWrite(f,pp,SIZEOF(byte));
BlockWrite(f,mas,SIZEOF(Gph));
CloseFile(F);
end;
end;
procedure TForm1.N6Click(Sender: TObject);
begin
form2.show;
end;
procedure TForm1.N4Click(Sender: TObject);
begin
edit1.Text:='1';
Button10.click;
Button6.Click;
Button9.click;
end;
procedure TForm1.TrackBar1Change(Sender: TObject);
begin
ugol:= TrackBar1.Position;
Button9.Click;
end;
end. |