Вы находитесь на странице: 1из 590

6

2011-05-16

, 2010-2011,

http://oleg-derevenets.narod.ru


.
( ).
,
.
, .
- .


,
Creative Commons Attribution-NonCommercial-NoDerivs
(
) 3.0 .
, ,
http://oleg-derevenets.narod.ru.


.............................................................................................................. 15
16 ............................................................................................................................. 19
1
.............................................................................. 20
2
.................................................................................................... 23
3
..................................................................................... 28
4
! ................................................................................................ 32
5
...................................................................................... 39
6
.................................................................. 46
7
................................................................................................. 50
8
................................................................................ 56
9
: ........................................................... 63
10
........................................................................................... 69
11
............................................................................................. 75
12
................................................................................. 79
13
................................................................................................. 86
14
......................................................................................... 96
15
-! ...................................................................................... 101
16
, ................................................................................. 106
17
.............................................................................................. 111
18
, ............................................................................................................ 116
19
: ................................................. 121
20
: ................................................................................ 127
21
............................................................................................................ 136
22
.................................................................................... 144
23
........................................................................................................... 148
24
.................................................................................................. 154
25
............................................................................................. 163
26
, !............................................................................ 171
27
!................................................................... 179
28
...................................................................... 186
29
- .............................................................................. 191
30
........................................................................................ 198
31
............................................................................ 211
32
............................................................................... 218
33
....................................................................................... 231
34
..................................................................................... 242
35
....................................................................................................... 249
36
...................................................................................... 257
37
................................................................................... 263
38
......................................................................................... 269
39
().............................................................................. 279
40
................................................................. 289
41
! .................................................................................... 295
42
, ............................................................................ 303
43
- ............................................................................... 317
44
.............................................................................................................. 332
45
............................................................................................... 341
46
............................................................................................... 351
47
......................................................................................... 359
3

48
.............................................................................................. 372
49
............................................................................................ 378
50
................................................................................... 391
51
................................................................................ 398
52
............................................................................. 408
53
.......................................................................................... 414
54
....................................................................................... 422
55
, , ...................................................................................... 436
56
, .................................................................. 442
57
..................................................................................................... 451
58
! ................................................................................... 464
59
............................................................................................ 481
60
............................................................................................. 497
61
................................................................................. 502
62
! ........................................................... 520
IDE Borland Pascal................................................ 529
Delphi........................................................ 547
IDE Pascal ABCNet ............................................................... 554
............................................................................ 557
(Borland Pascal)........................................................ 560
(Borland Pascal) ......................................................... 569
....................................................... 571
Borland Pascal.................................................................................... 573
MS-DOS .............................................. 578
.......................................... 581
..................................................................................... 583
..................................................................... 587
....................................................................................................................... 589


.............................................................................................................. 15
................................................................................................................ 15
?............................................................................................ 15
................................................................................................ 16
................................................................................................................ 16
?...................................................................................................... 17
..................................................................................................................... 18
16 ............................................................................................................................. 19
1
.............................................................................. 20
.......................................................................................................................... 20
......................................................................................................................... 20
..................................................................................................................... 20
.................................................................................................. 21
!....................................................................................... 21
.................................................................................. 21
.................................................................................................. 22
......................................................................................................................... 22
................................................................................................................................... 22
2
.................................................................................................... 23
............................................................................................ 23
................................................................................................................. 23
........................................................................ 24
IDE........................................................................................................ 26
................................................................................................................................... 26
3
..................................................................................... 28
? ......................................................................................................... 28
...................................................................................................... 28
...................................................................... 29
?........................................................................................................... 30
................................................................................................................................... 31
4
! ................................................................................................ 32
......................................................................................................... 32
IDE Free Pascal .................................................................................................. 33
............................................................................................................... 33
IDE Free Pascal ...................................................................... 34
......................................................................................... 36
................................................................................................................................... 38
5
...................................................................................... 39
.............................................................................................................. 39
................................................................................................................... 39
.............................................................................................................. 40
......................................................................................................................... 41
............................................................................................................... 42
............................................................................................................... 44
................................................................................................................................... 44
?............................................................................................................................... 45
6
.................................................................. 46
.................................................................................................... 46
............................................................................................. 47
............................................................................................................. 48
5

................................................................................................................................... 49
7
................................................................................................ 50
.................................................................................................. 50
, !................................................................................................................ 52
.......................................................................................................................... 52
- ......................................................................................................................... 53
................................................................................................................................... 54
? .............................................................................................................................. 55
8
............................................................................... 56
........................................................................................................................... 56
................................................................................................................ 58
........................................................................................................................ 58
......................................................................................................... 60
................................................................................................................................... 61
? .............................................................................................................................. 62
9
: .......................................................... 63
, ! .............................................................................................. 63
....................................................................................................... 64
................................................................................................................. 65
.............................................................................................. 66
................................................................................................................................... 67
? .............................................................................................................................. 67
10
........................................................................................... 69
! ? .................................................................................................................. 69
.................................................................................................................... 69
................................................................................................................. 70
........................................................................................... 71
................................................................................................................... 71
................................................................................................................................... 73
? .............................................................................................................................. 74
11
............................................................................................ 75
.......................................................................................................... 75
............................................................................................... 76
...................................................................................................................... 77
................................................................................................................................... 78
? .............................................................................................................................. 78
12
................................................................................. 79
........................................................................................................ 79
..................................................................................................... 80
............................................................................................................. 81
................................................................................................ 83
................................................................................................................................... 85
? .............................................................................................................................. 85
13
................................................................................................ 86
?.................................................................................................... 86
................................................................................................... 86
............................................................................................................ 87
.......................................................................................... 88
...................................................................................................... 88
................................................................................................. 89
............................................................................................... 93
................................................................................................................................... 94
6

?............................................................................................................................... 95
14
......................................................................................... 96
................................................................................... 96
.................................................................................................... 96
...................................................................................................... 97
, ............................................................................................ 98
................................................................................................................................... 99
?............................................................................................................................. 100
15
-! ...................................................................................... 101
, ! .................................................................... 101
................................................................................................................... 102
................................................................................................................................. 104
?............................................................................................................................. 105
16
, ................................................................................. 106
.................................................................................................... 106
................................................................................................................................. 109
?............................................................................................................................. 110
17
.............................................................................................. 111
............................................................................................................ 111
................................................................................................................................. 114
?............................................................................................................................. 114
18
, ............................................................................................................ 116
.................................................................................................. 116
........................................................................................................................ 117
..................................................................................................................... 118
............................................................................................................. 118
................................................................................................................................. 120
?............................................................................................................................. 120
19
: ................................................. 121
.................................................................................................................... 121
........................................................................................................... 121
............................................................................................... 124
................................................................................................................................. 126
?............................................................................................................................. 126
20
: ................................................................................ 127
..................................................................................................... 127
....................................................................................................................... 129
.................................................................................................................. 131
.................................................................................................. 132
!................................................................................................... 134
..................................................................................................... 134
................................................................................................................................. 134
21
............................................................................................................ 136
........................................................................................................................... 136
, ?.............................................................................................................. 138
..................................................................................................... 141
................................................................................................................................. 142
?............................................................................................................................. 143
22
.................................................................................... 144
............................................................................................................. 144
................................................................................................. 145
............................................................................................................... 146
7

................................................................................................................................. 147
? ............................................................................................................................ 147
23
.......................................................................................................... 148
........................................................................................................ 148
............................................................................................................... 148
.............................................................................................. 149
.................................................................................................................... 151
.................................................................................................. 151
Result .............................................................................................. 152
................................................................................................................................. 153
? ............................................................................................................................ 153
24
.................................................................................................. 154
...................................................................................................... 154
................................................................................................................. 155
................................................................................................. 155
.................................................................................................... 157
....................................................................................................... 158
...................................................................................................... 159
................................................................................................................................. 161
? ............................................................................................................................ 162
25
............................................................................................ 163
................................................................................................. 163
............................................................................................... 163
............................................................................................ 164
................................................................................................................ 165
.................................................................................. 167
..................................................................................................................... 167
............................................................................................... 168
................................................................................................................................. 169
? ............................................................................................................................ 170
26
, ! ........................................................................... 171
.................................................................................................. 171
...................................................................................................... 172
................................................................................. 172
................................................................................................................................. 177
? ............................................................................................................................ 178
27
! .................................................................. 179
...................................................................................................... 179
........................................................................................................... 179
................................................................................................ 180
.......................................................................................................... 180
- .................................................................................... 181
.................................................................................................. 182
! ..................................................................................................... 182
................................................................................................................. 183
................................................................................................................................. 184
? ............................................................................................................................ 185
28
...................................................................... 186
............................................................................................................. 186
.................................................................................................................... 188
......................................................................................................... 188
................................................................................................................................. 190
8

29
- .............................................................................. 191
, 1................................................................................. 191
, 2................................................................................. 195
................................................................................................................................. 197
?............................................................................................................................. 197
30
........................................................................................ 198
?....................................................................................................... 198
................................................................................................................... 199
............................................................................................... 202
..................................................................................................................... 204
....................................................................................................................... 206
............................................................................................ 206
............................................................................................................ 208
................................................................................................................................. 209
?............................................................................................................................. 210
31
............................................................................ 211
................................................................................................................. 211
........................................................................................... 212
...................................................................................................... 213
......................................................................................................................... 214
................................................................................................................................. 217
?............................................................................................................................. 217
32
............................................................................... 218
: ................................................................................... 218
.................................................................................................................. 220
, ........................................................................................... 221
.................................................................................................... 224
......................................................................................................................... 224
.................................................................................................................... 225
.............................................................................................................. 226
........................................................................................................... 229
................................................................................................................................. 229
?............................................................................................................................. 230
33
....................................................................................... 231
.................................................................................. 231
............................................................................................. 232
............................................................................................... 233
....................................................................................... 234
.............................................................................................. 235
......................................................................... 236
............................................................................. 239
................................................................................................................................. 240
?............................................................................................................................. 241
34
..................................................................................... 242
.................................................................................................. 242
....................................................................................................... 243
....................................................................................... 244
................................................................................. 245
.................................................................................. 247
? ...................................................................................................................... 247
................................................................................................................................. 247
?............................................................................................................................. 248
9

35
....................................................................................................... 249
................................................................................................. 249
, .................................................................... 249
...................................................................................... 250
........................................................................................................ 253
, .................................................. 255
................................................................................................................................. 255
? ............................................................................................................................ 256
36
...................................................................................... 257
...................................................................................................... 257
.................................................................................. 257
................................................................................................. 258
........................................................................................................ 259
( IN)....................................... 260
......................................................................................... 260
................................................................................................................................. 261
? ............................................................................................................................ 262
37
.................................................................................. 263
............................................................................... 263
.............................................................................. 264
, ............................................................................. 265
, ............................................................................. 267
................................................................................................................................. 268
? ............................................................................................................................ 268
38
........................................................................................ 269
, ? .......................................................................................................... 269
.................................................................................................. 269
....................................................................................................... 271
.......................................................................................................... 274
, ............................................................................................................ 276
................................................................................................................................. 277
? ............................................................................................................................ 277
39
().............................................................................. 279
................................................................................................................ 279
? .......................................................................................... 281
......................................................................................................... 281
....................................................................................................... 282
() ................................................................................... 285
.................................................................................................... 286
......................................................................................................... 286
................................................................................................................................. 288
? ............................................................................................................................ 288
40
................................................................. 289
- .............................................................................. 289
............................................................... 290
........................................................................................................ 292
................................................................................................................................. 294
? ............................................................................................................................ 294
41
!.................................................................................... 295
............................................................................................... 295
.................................................................................................. 296
....................................................................................................... 298
10

.................................................................................... 300
................................................................................................................................. 302
?............................................................................................................................. 302
42
, ............................................................................ 303
, ?............................................................................................. 303
................................................................................................. 303
................................................................................................................ 304
...................................................................................... 307
, , ! .............................................................................................................. 313
? !.................................................................................................. 314
................................................................................................................................. 316
?............................................................................................................................. 316
43
- ............................................................................... 317
........................................................................................................ 317
.......................................................................................................... 319
....................................................................................... 321
............................................................................................................ 324
, !........................................................................................................ 325
................................................................................................................................. 331
?............................................................................................................................. 331
44
.............................................................................................................. 332
........................................................................................... 332
......................................................................................................... 333
...................................................................................................... 334
....................................................................................................... 338
.......................................................................................................... 338
................................................................................................................................. 339
?............................................................................................................................. 339
45
............................................................................................... 341
................................................................................................ 341
...................................................................................................... 342
.............................................................................................. 346
........................................................................................................ 347
................................................................................................................................. 350
?............................................................................................................................. 350
46
............................................................................................... 351
? ..................................................................................................... 351
........................................................................ 351
................................................................................................................ 352
........................................................................................................ 354
................................................................................................................................. 357
?............................................................................................................................. 358
47
......................................................................................... 359
................................................................................................................... 359
.................................................................................................. 359
.......................................................................................................... 361
............................................................................................................. 364
............................................................................................ 365
............................................................................................... 367
........................................................ 367
................................................................................................. 369
................................................................................................................................. 370
11

? ............................................................................................................................ 370
48
.............................................................................................. 372
................................................................... 372
................................................................................... 373
..................................................................................................... 376
................................................................................................................................. 377
? ............................................................................................................................ 377
49
............................................................................................ 378
............................................................................................................ 378
................................................................................................ 378
- .............................................................................................................. 383
................................................................................................................................. 389
? ............................................................................................................................ 390
50
................................................................................... 391
! ................................................................................................................ 391
............................................................................................................................... 391
...................................................................................................................... 392
..................................................................................................... 395
................................................................................................................................. 397
? ............................................................................................................................ 397
51
................................................................................ 398
................................................................................. 398
................................................................................... 399
, ......................................................................................... 400
.................................................................................................... 401
, .................................................................... 402
.................................................................................... 403
............................................................................................... 404
..................................................................................................... 404
.................................................................................................... 404
................................................................................................................................. 407
? ............................................................................................................................ 407
52
............................................................................. 408
............................................................................................. 408
!........................................................................................... 408
............................................................................................................ 409
...................................................................................................... 409
, .................................................................................. 410
................................................................................................................................. 412
? ............................................................................................................................ 412
53
.......................................................................................... 414
........................................................................................................ 414
....................................................................................... 419
................................................................................................................................. 420
? ............................................................................................................................ 421
54
....................................................................................... 422
.......................................................................................................... 422
..................................................................................................... 423
..................................................................................................................... 423
............................................................................................................. 427
.................................................................................... 428
..................................................................................................... 429
12

........................................................................................ 433
................................................................................................................................. 434
?............................................................................................................................. 435
55
, , ...................................................................................... 436
.................................................................................................. 436
................................................................................................................... 436
.............................................................................................................. 436
........................................................................................................................... 437
?............................................................................................................................. 441
56
, ................................................................... 442
?............................................................................................................. 442
! ..................................................................................................................... 445
................................................................................................................................. 450
?............................................................................................................................. 450
57
...................................................................................................... 451
......................................................................................... 453
..................................................................................... 454
........................................................................................................... 457
................................................................................................................................. 463
?............................................................................................................................. 463
58
!.................................................................................... 464
........................................................................................................... 464
.................................................................................................................. 469
! .................................................................................................................... 470
.............................................................................................................. 476
................................................................................................................................. 479
?............................................................................................................................. 479
59
............................................................................................ 481
......................................................................................... 481
.............................................................................................................................. 482
.................................................................... 482
......................................................................................................... 487
..................................................................................................... 488
............................................................................................................. 491
........................................................................................................... 491
.................................................................................................................. 493
.................................................................................................... 494
................................................................................................................................. 496
?............................................................................................................................. 496
60
............................................................................................. 497
.......................................................................................................... 497
....................................................................................................... 498
................................................................................................................................. 501
?............................................................................................................................. 501
61
.................................................................................. 502
- ...................................................................................................................... 502
............................................................................................................. 503
.................................................................................................................... 503
.................................................................................................................... 504
.................................................................................................................... 506
.......................................................................................................... 507
............................................................................................. 508
13

.................................................................................................... 513
................................................................................................................... 514
.............................................................................................. 517
................................................................................................................................. 519
? ............................................................................................................................ 519
62
! ........................................................... 520
......................................................................................................... 520
, ! ................................................................................................. 523
IDE Borland Pascal................................................ 529
IDE Borland Pascal, .......................................................... 529
IDE Borland Pascal .......................................................................................... 530
............................................................................................. 536
.......................................................................................... 536
IDE ........................................................................................................ 538
IDE ..................................................................................... 540
....................................................................................... 542
Turbo Pascal School Pak .................................................................................................... 546
Delphi........................................................ 547
................................................................... 547
........................................................ 548
.......................................................................... 551
IDE Pascal ABCNet ............................................................... 554
............................................................................ 557
(Borland Pascal)........................................................ 560
(Borland Pascal) ......................................................... 569
....................................................... 571
Borland Pascal.................................................................................... 573
MS-DOS .............................................. 578
.......................................... 581
..................................................................................... 583
..................................................................... 587
....................................................................................................................... 589

14


, ,
, .


! , .
, , , 90-,
. !
.
: ?
!
,
. 10-15, ,
?. ,
.
, .
, .
: ,
, .
? ! , , -, -
. ,
. , ! ? ,
.

?

:
!
: 90-?
, , ,
. ? ,
!
, ? ,
.

, ,
.
, ,
, .
, . ?
, ?
, .
, . , ,
: ,
.
? ?
. ? ! ,
. , ? ,
, ! ? ,
, .


, -. ,
. , , .
: -? !
, ,
. ! ,
, . ,
. ,
.
, .
, , , ... - , ...
! ?
, ,
.
, ? . ,
, , , - .
, .
, ? ,
, . , , ....
; ,
, . ?



. ,
, ,
16

, , ,
. , ? , ,
. , .
! -
?
, . ,
.
. ,
.
, !
. .
,
.
. ,
( , ).
, , .
.
, . ,
(, ).

.
!
.
!
. ,
. ,
. ,
.
, , .
, .

?
, , ? .
.
1- 4-
.
.
5- 31-
.
.
17

32 35
.
36 58
. , ,
.
59 60 ,
61 - .
62-
.
, , - ,
, .
, ,
,
. , ?
. , ,
,
. : , , .
. ,
, .
,
,
. .
.
, !

. , .
, -
? , ,
!

,
. ! , , :

oleg.derevenets@gmail.com

18

16
!, . ?
, . .
, , , , !.
? ?
? , .
: ? , ,
!
, ,
. , , ?
, .
. ? ?, .
, , ?
! , , ?
? , .
, .
,
, . ,
, .
.
, .
? ,
. ,
, , .
, -, ,
. ?
, . , , ,
. ,
, ,
!
, , ,
. , ,
. , ,
.
, .
, .
, .
, .
,
. ,
!
19

1

, ,
? . ? ,
, .

? !
. ,
! , ?
, .
? , , IBM-
. ,
. .

MS-Windows, .

, , ?
, .
,
, . ,
MS-Windows.


, ,
, . ,
? ? ,
? ?
? Notepad
(). , .
.
, .
,
. .
.
? ,
3- . ,
, ...
!

20

. ,
. ,
.
. , ,
. .
,
. , ! -
( )
.
. !
? ,
. ,
!



. , ,
.
,
.
().

!
-
. , ,
, .
? ? ?
,
.
.


, .
: , , . -
? ?
! , !

21


, -
, . ,
, .
, .

,
:
Borland

, ,
..;

File Name

(, );

Begin

().

.
.
,
MS-Windows.
,
.
, ,
, .

.
!

22

2

, !
,
. ,
, !
, , .
, ,
. :
!
, , ,
!
, . ,
, , .
, . ,
. , !
.
, .
, .


, .
. !
,
. :
- . ,
, ,
. ,
,
. , ,
, , .
, ,
, .
? ,
. , ,
. , ,
.


, ,
EXE. , ,
. - ?
23

, Total Commander. ,
F3 (. 1).

. 1

? , , !
, . ,

! ?
? , ,
.


, .
? ?
. ,
, .
, .
,
.
, ? ?
, ,
? , .
,
, .
. ,
, ,
.
. 2,
: , .

24

,
,

EXE-,
,

EXE-
( )

. 2

?
,
.
, , . ,
, ,
. , , .
, , .
.
.
Var a, b : integer;
Begin
Readln(a,b);
Writeln(a*b = , a*b);
End.

, . , ,
, - .
25

, , .
,
, .
, - .
EXE- :
, , ,
. -
? . ,

. , , ,
.

IDE
, , ,
: . ,
.
- .
, ,
.
:
, .
IDE (Integrated
Development Environment). .
IDE? .
IDE , , ,
, . IDE
,
.
IDE .

,
, .
.
,
.
.
.

EXE- -.

26

(IDE)
, ,
.

27

3

,
! ?
. ,
, . , ,
. ? , ?

?
. ,
, .
,
.
?
, .
? ! , ,
: , .
, ,
. ,
?


.
,
. .
,
.
. ,
, ,
.
.
, ,
.
,
. ,
. ? ,
, .
, .
,
. ,
28

MS-DOS.
.


, ,
. ,
?
, MS-Windows MS-DOS,
. ,
MS-Windows:

MS-DOS
, . 3.

. 3 ( )

.
. ,
, .
,
MS-Windows. : DIR
, CLS , EXIT .
DIR (
) Enter.
.
(. 4).
29

. 4 DIR

, ,
.
DIR . CLS ( )
, .
EXIT () ,
.
,
, MS-Windows .
Alt+Enter,
MS-Windows.
(, MS-Windows Vista)
.
, :
VER

MEM

TREE

,
5, .

Delphi, : ?
!
30

, IDE Delphi .
,
. ,
, . .
.
,
. ,
, ?
,
.

,
, , .

.
.

31

4
!
,
(IDE). , ,
, .


, IDE , ,
, . IDE
, , :
Borland Pascal 7.0 (7.1);
Free Pascal;
Delphi;
Pascal ABCNet.
: IDE ?
? ?
, IDE ,
.
Borland Pascal IDE , Borland
MS-DOS. IDE
7.0 7.1. ,
(,
).
Delphi Borland, Borland
Pascal. .
Delphi
.
Free Pascal. Borland,
.
IDE,
Borland Pascal. Free Pascal ;
, IDE
, MS-Windows.
Pascal ABCNet , IDE.

Net, Microsoft. ABC
, .
32

4
!

, ?
Pascal ABCNet. .Net
(
). IDE,
? Delphi .
Borland Pascal , .
Borland . , Free Pascal?
.
.
, ,
IDE ( ABCNet, ).
,
:

Borland Pascal;

Delphi;

Pascal ABCNet.

IDE Free Pascal


IDE Free Pascal.
, . , ,
www.freepascal.org. Downloads,
- .
Intel
MS-Windows
www.freepascal.org/down/i386/win32.var

, - .
( ftp.freepascal.org)
fpc-2.4.2.i386-win32.exe
,
, .
, . IDE
C:\FPC\2.4.2 ( 2.4.2),
IDE Free Pascal.


, , ,
. ? ,
33

4
!

, .
: , .
. , ,

C:\User\Pascal
, IDE, .

. ,
, ,
(. 5 ).

. 5 -

(. 5 )
.
OK.

IDE Free Pascal


. IDE
.
, (. 6).

34

4
!

. 6 -

(Yes), IDE
FP.CFG. ,
IDE, .
, , IDE,
. IDE,
Options Environment Preferences (. 7)

. 7 -

(. 8).
Video mode . ,
80x25 color .
, . 8.
OK
.

35

4
!

. 8 -

IDE Free Pascal , . 9. FPC


Free Pascal Compiler
.

. 9 - IDE Free Pascal

IDE , .
. ,
,
, .


IDE Free Pascal
:
http://www.freepascal.org/down/docs/docs-ftp.freepascal.org.var
36

4
!

(PDF, CHM,
HTML). doc-html.zip, .
HELP ,
IDE Free Pascal, zip- .
fpctoc.html,
.
IDE Free Pascal,
.
IDE Help Files (. 10).

. 10 -

(. 11).

. 11 -

New fpctoc.htx, ,
fpctoc.html (. 12).

37

4
!

. 12 -

Open, ,
OK.
( fpctoc.html), IDE Free
Pascal F1 Ctrl+F1.

(IDE),
,
.
,
IDE Free Pascal.
IDE.
IDE Free Pascal
() ( ).
,
, IDE Free Pascal.

38

5


, .
?
. ,
.
!, , !


IDE Free Pascal, ,
. ,
File New (. 13).
NONAME00.PAS, . (00,
01, 02 ..) .

File New

. 13

,
C:\User\Pascal. , .
.
, MS-DOS. ,
,
PAS. ,
( !).
, !
, .
39

, .
, .
, P ( Pascal),

. ,
5- : P_05_1.PAS.
. F2,
(. 14). ,
PAS , .
Enter OK
, P_05_1.PAS.
P_05_1

. 14


, ,
. , ,
.
begin
end.

, : BEGIN , END
. ?
. BEGIN END
, .
40

, .
, ,
. !
,
BEGIN END
. , ,
. , BEGIN -
END.
,
: Begin, BEGIN, begiN, .
, . ,
. ,
(,
, ). , !
END, ,
! ,
END, , .
, ,
F2 . , IDE
P_05_1.PAS, .
, !
, ,
. , ,
! , .

? ?
EXE-? : F9 !
,
(. 15).

41

. 15

.
, P_05_1.PAS
P_05_1.EXE.
EXE-
. .
? (
), MS-Windows ,
.
, , .


IDE ,
. - ,
. ,
.
, BEGIN
END , .
Writeln(!)

. ,
Writeln. : Write , Line ,
. Writeln
, .
, .

, , .
42

, Writeln -
, ? ,
. !,
( ).
, , .
.
, !
--- Borland Pascal 7.0 ---
, !

, ,
.
, , .
, 255 . ,
Writeln.
, .



?
, .
'

, ,
, !
,
.
begin
Writeln(!)
end.

,
. ? F2
F9. ,
. ,
.
43


P_05_1.EXE, ,
. ? ?
,
, !
, ,
! , .
, IDE,
Ctrl+F9. ? ? ?!
, . , IDE
, , .
, IDE
Alt+F5. , (. 16).

, !

. 16 IDE

IDE Free Pascal,


. ,
!. , IDE,
. ,
(Ctrl+F9) (Alt+F5).

.
, ,
Begin End .
, .
Writeln
.
.
44

,
. 255 .
EXE- ,
F9.
,
, .
IDE.
Ctrl+F9.
( IDE)
Alt+F5, IDE
.

?
,
. ,
. ,
, . .
) .
begn
Writeln(!)
end

, . ,
. ?
) ?
begin Writeln(Begin

End.) end.

) , ,
, .

, .
(;).

45

6

, ,
.


, ,
PAS. ,
F3,
(. 17).

. 17

.
( PAS),
. ,
. Open,
Enter, .
.
, ,
, . IDE Free
Pascal ,
.

46


, MS-Windows, IDE
Free Pascal . . 18,
.

(1-9)

( : )

. 18

.
? .
, .


.

? ,
; F2
Save.

.
F2,
. (
),
IDE (. 19).

47

.
?

. 19

Yes ,
No . Cancel ,
.
, .


, !
. . ,
, IDE Free Pascal .
.
: , . ,
? ? , !
, ,
.
. ,
, , ,
. ,
. EXE-
. ?
, . ,
, .
.
. , BEGIN.
egin
Writeln(!)
end.

F9. ?
: BEGIN expected. ,
48

BEGIN.
,
IDE (Appendix C, Compiler messages), .
,
( ).
begin
Writeln(!)
end.

: String exceeds line, :


. ,
,
, . ,
. , .
,
.
?
? . ? ,
. ,
! , ,
.

IDE
.
IDE Free Pascal ,
(, ).
,
, , .
Pascal .
, ,
.

49

7

,
, .
----------------------- !
!

------------------------


P_07_1.PAS. ,
File New,
F2. , .
, .
begin
Writeln(------------------------)
Writeln( !)
Writeln( !)
Writeln( )
Writeln(------------------------)
end.

:
, . ,
! , , F9 ?
(. 20)!

50

. 20

? , - .
: , . ,
? ?
.
.
, - .
, .
.
,
. !
, (;).
.
, ,
.
. , .
.
, ,
. .

51

7

begin
Writeln(------------------------);
Writeln( !);
Writeln( !);
Writeln( );
Writeln(------------------------)
end.

,
END? , END , . ,
,
. Ctrl+F9
, Alt+F5.

, !
, Alt+F5
, . .
, ReadLn. ,
Writeln, : Read , Line ,
. ReadLn :
, , ,
Enter. . , .
? , ? ,
! .
begin
Writeln(------------------------);
Writeln( !);
Writeln( !);
Writeln( );
Writeln(------------------------);
Readln
end.

? !
, ( Enter!).

: ,
. .
,
. , :
52


. .
- , ? !
: , . ,
. , , ,
: , , ,
. : , ,
, ...
, .
, ,
. ,
,
.

-
, ,
. ,

. ,
. , . ,
. ?
- , .
,
. -
,
.
, -.
. ? ,
, - , . ,
.
- (. 21).

53

Begin

End

) P_05_1

---------------
!

---------------
Enter

) P_07_1

. 21 -

,
BEGIN END.
,
. ! ,
, -.

.
Writeln Readln .
54

.
.

.

.
,
(-) .

?
) .
, Enter.
, :
Enter

. ?
) ,
. .
- ?
) -, ,
.

55

8

?
? !
, .
.
, . , ,


.
. ,
.
, . ?
. , . ,
, .
, 3,14
( ). ,
, .
, 3,14 3,1416?
. -
!
,
.
, .
:
, .
.
, , ,
. CONST,
, .
const _ = _;

, .
, Line .
.

56

8

const Line = ---------------------------;

: ,
!
, .
Writeln(Line);

Writeln -
, Line.
CONST
, .
Const C1 = !;
Pele = ;

, CONST,
. ,
! BEGIN,
. ,
.
const Line = ---------------------------;
begin
Writeln(Line);
Writeln( !);
Writeln( !);
Writeln( );
Writeln(Line);
Readln
end.

--, . ,
! ,
, , ?
, .
const Line = ***************************;

,
,
.
57

. ,
, .
(IDENTIFIER).
, .
.
() ,
.
, .
255 ,
32 ( , ).
.
, .
. ,
, Pascal PASCAL
.
.
A, b, C

R1, U28, _13_

Cosmos, ABBA

NextStep, Next_Step

- ,

.
7Up

End

, ,
. ,
C (, Cline).

, P_07_1
, .
:
, .
.

58

8

?

,
Enter

:
. .
,
. ,
.
,
.
- (, ).
? , , .
(VARIABLE).
, .

. : , .
, , .
, ,
!
, , , .
BEGIN,
VAR ( VARIABLE).
,
.
, .
var _ : _;

, ,
. , ?
, .
, , .
, .
. ,
, .
, . .
, ,
: ?
, ?
59

. ,
.
,
,
. STRING, , .
- .
. ?
Name, . , Name
STRING .
var Name : string;

, ,
.


, . ,
, .
Readln.
, Enter.
!
, .
, . .
Readln(Name);


,
Name

Enter.

, Enter.
,
. ,
, ,

?
Writeln? ! .
.
Writeln(Name);

, !
, .
? !

60

, , .
.
Writeln(, , Name);

, ( ),
Name.
.
P_08_1.PAS, .
var Name : string;
begin
Writeln( ?);
Readln(Name);
Writeln(, , Name);
Writeln( Enter); Readln;
end.

, , .

,
.
.

.
.
,
.
Readln,
Writeln.
Writeln
, .
.
,
.

61

?
) ,
?
const Champ = !';
var

Team : string;

begin
Writeln( ?);
Readln(Team);
Writeln(Team, Champ);
Readln
end.

) .
begin
const Pele = ;
Writeln( - , Pele);
Readln
end.
begin
Writeln( ?);
var Name : string;
Readln(Name);
Writeln(, , Name);
Writeln( Enter); Readln;
end.
const Pele = ;
begin
Writeln( );
Readln(Pele);
Writeln(Pele);
Readln
end.

62

9
:
, , ,
, .

, !
P_09_1
, , .
( ).
?

, !
Enter

,
, . ,
, .
var

N : string;
F : string;

N F Name ()
Family (). .
var

N, F : string;

, , ,
.
, :
, , , ,
.
, !

? ! .

63

9
:
Writeln(, , N, , F, !);

Writeln !
: ,
, .
, .
var

N, F : string;

begin
Writeln(?); Readln(N);
Writeln(?); Readln(F);
Writeln(, , N, , F,!);
Writeln( Enter); Readln;
end.


, .
, :
, .
.
, B
A. .
A := B;

:=
. ,
, ...
, . , ,
?

64

9
:
var A, B : string;
begin
A:= ' ';
Writeln(A);

B:= ' ';

Writeln(B);

B:= A;
Writeln(B); Readln
end.

, .


A B
(), .
B:=A B A,
, .
:
? , .
!


, ? ,
? . : .
, , .
?
. -
.
, !
. , , . ,
(. 22).

. 22 +

. 22 .
,
. S ,
65

9
:

( N F ,
).
S:= , + N + + F + !;

, :=
, .
.
var

N, F, S : string;

begin
Writeln(?); Readln(N);
Writeln(?); Readln(F);
S := , + N + + F +!;
Writeln(S);
Writeln( Enter); Readln;
end.

, .


, .
var

S : string;

begin
Writeln(S);
S:= ;
Writeln(S);
S:= S + !;
Writeln(S);
Writeln( Enter); Readln;
end.

S . , ,
Writeln(S)? !
. ,
.
, .
,
. : ,
- ! , ,
66

9
:

. : Readln,
.
S ,
.
S:= S + !;


. S !.
, , . !

.
Writeln
. .
:= ,
, ,
.
.

Readln, .

.

?
) ?
const Pele = ;
begin
Writeln(Pele = + Pele);

Readln;

end.

67

9
:

) ?
var A, B : string;
begin
A:=123;

B:=456;

Writeln(A+B= + A + B);

Readln;

end.

) ?
const Pele = ;

) , : 1)
, 2) , 3) 4) .
( , ):
:

: : :

:
Writeln, .

68

10

, ,
. ,
.

! ?
, .
, , pascal.
, .
P_09_1 ,
.


? ?
: ? ?
? .
: ,
, . , ,
, .
. ,
.
.
: IF , THEN
ELSE . .
IF <> THEN <_1> ELSE <_2>
.
, , . ,
,
.
, ? .
,
, . ,
S .
.

69

10

if S = pascal then Writeln(!) else Writeln (!)

.
.
if pascal = S
then Writeln(!)
else Writeln (!)

S pascal ,
.
THEN ELSE (
). ,
. ,
.
7 .
, ,
. ,
.
. -,
(. 23).

THEN

ELSE
IF

_1

_2

. 23

,
.


? -.
, , .

70

10

var

S : string;

begin
Writeln(?); Readln(S);
if S = pascal
then Writeln(!)
else Writeln(!);
Writeln( Enter); Readln;
end.

Writeln(!)
? , !
Writeln(!).
IF, .
.


? ? ,
.
, .
,
.
IF <> THEN <>
- . 24.

IF
THEN

. 24 -



(P_09_2).

71

10

var

S, R : string;

begin
Writeln(?); Readln(S);
R:= !;
if S = pascal
then R:= !;
Writeln(R);
Writeln( Enter); Readln;
end.

R,
!.
!,
.
.
. ,
.
, ?
, .
.
.
- . ,
-, . 25 .

72

10

P_10_1

P_10_2

IF

IF

Enter

Enter

. 25 -


, .
IF :
THEN ELSE.
.
IF
THEN.

73

10

?
)
( , , ).
) , , ,
!.

74

11

, 10- ,
. . ,
, , : ! ,
!. : ! !.
, ,
. - . 26.
?

, !

. 26 ,


: , ,
- , , .
, , .
if S = pascal
then

Writeln( !);
Writeln(, !);
Writeln(!);

else

Writeln(!);
Writeln( !);

. ,
? .
, , ?
IFTHENELSE,
75

11

! ,
: Error in statement .
,
. ?
, - .
! ,
, .
BEGIN END.

.
if S = pascal
then begin
Writeln( !);
Writeln(, !);
Writeln(!)
end
else begin
Writeln(!);
Writeln( !)
end;

, BEGINEND ,
.
BEGINEND? !
, . ,
, : .
BEGINEND, .
,
.
END ?
! , ,
END .


, , THEN ELSE
. , ? .
, .
?

76

11

.
; . ,
, , .
. ?
THEN ELSE,
. , , .
BEGIN END ,
.
,
, , . , ,
P_11_1 (
).
var

S : string;

begin
Writeln(?); Readln(S);
if S = pascal

then begin

Writeln( !);
Writeln(, !);
Writeln(!)
end

else begin
Writeln(!);
Writeln( !)

end;
Writeln( Enter); Readln;
end.

,
, .
, {}.
(**).
.
{ }
{

}
(* *)

? .
, , ,
77

11

, . ,
. ,
. .
-.
?
. , .
, ,
, . ,
.

BEGINEND
.
.

. , .
.
.

.

?
) ?
) ,
.
Writeln( ? ?); Readln(S);
if S = then
begin
Writeln( !);
Writeln( ?);
end;
else begin
Writeln( !);
end;

78

12


, .
- ,
. , ,
. ,
!.
,
, .
. . -
(. 27).

:
!

:
!

. 27 -

, ,
, , .
: 1)
? 2) ?
. ,
.
. S,
79

12

, , Enter.
.
if S = then ...

,
( !).
, ?
, !
IF, ,
.


, , .
,
.
; :
REPEAT UNTIL .
,
. ?
REPEAT , UNTIL ,
.
REPEAT
< 1>
. . .
< N>
UNTIL <>

- :
, . -
; 1 2
, .
, 3.

80

12

REPEAT

UNTIL

. 28 -

.
P_10_1.
REPEATUNTIL ,
P_12_1.
{ P_12_1 - }
var

S : string;

begin
repeat
Writeln(?); Readln(S);
if S = pascal
then

Writeln(!)

else Writeln(!);
until S=; { , S }
end.

.
, .


? ! .
, - : !
. ? ? !
.
, . 29.
81

12

Repeat

IF

IF


:
!

:
!

?
Until

. 29 -

- ;
, .
, , S.
if S <> then ...

- .
THEN , S .
, IF S=.
,
. , P_12_2,

. ?
, , . ,
.
82

12

{ P_12_2 }
var

S : string;

begin
repeat
Writeln(?); Readln(S);
{ , }
if S<> then
if S = pascal
then

Writeln(!)

else Writeln(!);
until S=;
Writeln( ! Enter); Readln;
end.

,
. , ?


?
, . . ,
.
,
, , .
BREAK ( ).
, , UNTIL.
- .
, BREAK .
if < > then Break;

BREAK .
, - BREAK (. 30).
.

83

12

Repeat

Break

IF

Until

. 30 - Break

, BREAK ,
UNTIL.
.
if S= then break;

, ,
.

84

12

{ P_12_3 }
var

S : string;

begin
repeat
Writeln(?); Readln(S);
{ , }
if S= then break;
if S = pascal
then

Writeln(!)

else

Writeln(!)

until S=;
Writeln( ! Enter); Readln;
end.

,
, . , BREAK
, UNTIL.

REPEATUNTIL
, .
UNTIL,
, .
BREAK
UNTIL.

?
) REPEAT UNTIL?
) UNTIL ?
) P_11_1
. ?
) .
, , .

85

13

, ? ,
, ! . ,
, .
,
. , ?
, , .
! ,
! ,
! .
(
)
. , , ,
.

?
. -
, , , ?.
, ,
. ?
, :
. , .
, , , ,
, .
, . !
? , , .


, . ,
, , ?
-, : ,
. , - ,
, , ,
.
.
, ? ,
.
(- BIT).
: ,
1024 . , ?
86

13

, .
(, , )
. , -
.
.

, .
, ,
, 0 1.
, : . :
, , . ,
, , .
, .


,
.
,
. .
.
var

A, B, C : Boolean;

.
, ,
: TRUE FALSE . ,

. .
A:= true;
B:= false;
C:= B;

.
A:= true;
B:= false;
C:= B;

: TRUE FALSE , ,
.

87

13


.
, . ,
.
, Writeln
TRUE FALSE. , .
var

B : Boolean;

begin
B:= false;

Writeln(B);

B:= true;

Writeln(B);

end.

, Readln,
, . ?
, . .
, , .
.
: TRUE
1, FALSE .
B .
var

S : String;
B : Boolean;

begin
Writeln( 1 TRUE FALSE);
Readln(S);
if S=1 then B:= true else B:= false;
end.

? , ,
.



. ,
, . ,
, , ?
, , , , TRUE FALSE.
, ,
, . ,
88

13

.
.
B := S=1;

S=1,
B TRUE, S 1 FALSE
.
,
, , .
.
if B
then { , B=true }
else { , B=false }
repeat
{ , B=false }
until B

.
, .


, ,
.
. ,
,
, . ,
TRUE, FALSE. ,
,
. ,
.
. ,
, . 31.

. 31 ,

89

13

,
, A B.
.
var

A, B : Boolean;

S: string;

begin
Write( A: );

Readln(S);

A:= S=1;

Write( B: );

Readln(S);

B:= S=1;

, , TRUE 1.
Write,
Writeln. ,
.
.
-, , . ,
.
.
S:= ;
if A then
if B then S:= !;

S .
, TRUE. ,
.
. , ,
? ,
! ?
. ,
, .
: ,
A B. .
,
AND,
A B. .
if

A and B
then S:= !
else S:= !;

.
.
90

13

{ P_13_1 }
var

A, B : Boolean;

S: string;

begin
{ }
Write( A:);

Readln(S); A:= S=1;

Write( B:);

Readln(S); B:= S=1;

{ }
if

A and B
then S:= !
else S:= !;

Writeln(S); Readln
end.

,
?
, ,
(. 32).
A

. 32 ,

: , A
B. , -
OR. .
if

A or B
then S:= !
else S:= !;

(. 33).

91

13

. 33 ,

?
: , A B C
D E. . , !
.
if

A and B or C and D or E
then S:= !
else S:= !;

! .
AND () OR ().

. ,
: (AND)
(OR). ,
. . 34 ().
A

. 34 ,

: , A
B C D. ,
, .

92

13

if

A or B and C or D
then S:= !
else S:= !;

, ,
: A or (B and C) or D. , !
.
if

(A or B) and (C or D)
then S:= !
else S:= !;

, . 35.
. , TRUE
( ).
A

. 35 ,

, : ,
. . -
: NOT.
.
if

not A
then S:= !
else S:= !;

,
, .
,
.


, ,
.
() .
93

13

,
. , .
NOT (). ,
. ,
.
, .
.
NOT

FALSE =

TRUE

NOT

TRUE

FALSE

AND (). , NOT, ,


OR. TRUE,
TRUE.
FALSE AND

FALSE =

FALSE

FALSE AND

TRUE

FALSE

TRUE

AND

FALSE =

FALSE

TRUE

AND

TRUE

TRUE

OR (). ,
. TRUE,
TRUE.
FALSE OR

FALSE =

FALSE

FALSE OR

TRUE

TRUE

TRUE

OR

FALSE =

TRUE

TRUE

OR

TRUE

TRUE

, .
, .
.

( ).
.
,
. .
()
. : TRUE ()
FALSE ().
94

13

OR, AND, NOT


.
.

.

?
) ?
.
S:=123;
Writeln (S=123);

) .
if (S=) and (A or B) then ...

) ,
. 36. ?
F

E
G

. 36

95

14

.
. ,

, .
, ,
- .


.
, .
, ,
. , .
, . :
.
, .


: STRING BOOLEAN
.
, INTEGER,
. ,
( ), 10, 25, -14.
.
var N, M : integer;

,
, , , .
N := 19;

M :=-25;

M := 20 + 3*N;

: (+), (-),
(*), (DIV) (MOD). DIV
MOD . (
).

96

14

N := 10 div 3;

{ 3 }

M := 10 mod 3;

{ 1 }

,
, .

(=), (<>), (>), (<), (>=),
(<=). , ,
, .
var

X, Y: integer;
B: Boolean;

begin
X:=5;

Y:=10;

B:= X=Y;

{ B = FALSE }

B:= X<Y;

{ B = TRUE }

B:= X=Y-5;

{ B = TRUE }

end.

, ?
, . ,
Readln, Write Writeln, .
Readln(X);
Writeln(X);
Writeln(Y=, X+10);

Y=
X+10.
.


, . ,
.
.
,
. , , .

97

14

A = 7
B = 7
A*B = 47
, !

. 7, 7 47 . ,
, .
- , . .
- (. 37).

Repeat

Break

IF

Until
FALSE

. 37 -

REPEAT...UNTIL,
FALSE. ,
BREAK, -.

,
, .

98

14

{ P_14_1 , }
var

A, B, C : integer;

{ }

R: Boolean; { }
S: string;

{ }

begin
repeat
{ }
Write( A = );

Readln(A);

Write( B = );

Readln(B);

Write( A*B = );
if C=0 then break;

Readln(C);

{ , C=0 }

{ }
R:= A*B=C;

{ R=true, }

if R
then S:= , !
else S:= , !;
Writeln(S);
until false; { }
end.

.
,
, . .


(INTEGER).
,
.
,
, .
Readln
Write Writeln.

99

14

?
) .
var

N, M : integer;
S : string;

begin
N:= 10;
S:= N + 5;
M:= S - 1;
if S=N then;
end.

, .
) P_14_1, Break. ,
-, ?
) P_14_1 R
S? . ?

100

15
-!
- ,
. , ,
. ? ,
-!. , ,
, . ,
.
.

, !
. , ,
. ,
, ,
, .
, , .
?
,
, ! , ,
, , ?
!

. ,
. , ,
, .
,
( ,
).
, , , (
). ,

, , .
.
, ,
.

. .
,
, .
, ! -
?
101

15
-!

. , ,
Readln Writeln.
, .
?
, ,
(, ). ,
, , , . ,
.


,
1 10.
-, ! ,
Random,
, .
N, .
N-1. ,
X 0 9.
X:= Random(10);

, Random .
, , .
{ P_15_1 Random(100) }
begin
Writeln( Random(100) );
Writeln( Random(100) );
Writeln( Random(100) );
Writeln( Random(100) );
Writeln( Random(100) );
Readln;
end.

, Random.
(100),
. 0 99. ,
Random .
.
, ? ! ,
Random .
. .
102

15
-!

,
!
.
Randomize ( ) .
,
Random
. ,
, .
{ P_15_2 Random(100) Randomize }
Begin
Randomize;
Writeln( Random(100) );
Writeln( Random(100) );
Writeln( Random(100) );
Writeln( Random(100) );
Writeln( Random(100) );
Readln;
end.

,
1 10 ( 0 9). ,
.
X:= 1+ Random(10);

{ 1 10 }

, ,
( , , ).

103

15
-!
{ P_15_3 -, 2 }
var

A, B, C : integer;

{ }

begin
Randomize;

{ }

repeat
A:= 1+ Random(10);

B:= 1+ Random(10);

Write( , A, x ,B, ? );
Readln(C);
if C=0 then break;

{ , C=0 }

{ }
if A*B=C
then Writeln(, !)
else Writeln(, !);
until false; { ! }
end.

.
Write( , A, x ,B, ? );

Write :
. , A=3 B=7 :
3 x 7 ?.
.


, .
,
,
.

Random Randomize.
Random(N) ,
0 N-1.
,
Randomize.
Randomize
Random .

104

15
-!

?
) :
10+Random(10);
Random(20);
Random(10) + Random(10);
!
) ?
.
var x : integer;
begin
repeat
x := Random(20);
Writeln(x);
until x=1;
end.

) Randomize?
? ?

105

16
,
!
-: , !
: , .
- , (
). . ,
, , . -
, ,
.
. ,
? : , .
.
, , . ,
, .


.
. -,
, .

, .
? , ,
. - . 38.

106

16
,

REPEAT




Break
R
R=1
R=2
R=3

1
2
3
4

Until FALSE

. 38 -

,
R.
if R=1
then S:= 1
else if R=2
then S:= 2
else if R=3
then S:= 3
else S:= 4;

,
. ?
,
!
107

16
,

,
CASE ( ). IF,
, CASE
; .
case X of
n1: _1;
n2: _2;
. . .
else _n
end;

: CASE, OF, ELSE,


END. X ,
: n1, n2 ( ).
. X n1,
_1, X n2, _2 .
X , ,
ELSE. ELSE ? .
. Random(20)+1
1 3, S
, .
case Random(20)+1 of
1: S:= ;
2: S:= ;
2: S:= ;
else S:= ;
end;

CASE ( )
, .

108

16
,
{ P_16_1 }
var

S: string;

begin
Randomize; {

repeat
Write( : ); Readln(S);
if S= then break;

{ , }

case Random(5) of
0: S:= ;
1: S:= ;
2: S:= ;
3: S:= , !;
else S:= , ;
end;
Writeln(S); { }
until false; { }
end.

,
Random, .


CASEOF ELSEEND.
CASE ,
.
( ).
CASE
. ,
, ELSE. ELSE ,
.
,
BEGINEND.

109

16
,

?
) , CASE
Random(100)?
) , ,
(, ).

110

17

, ,
, .
, ?
. ,
, 15 , :
;
1-2 ;
3-5 ;
6 .


, (. 39),
.

= 0
= 0

. 39 - ,


. (
111

17

), . ?
, .
.
: 1 10.
REPEAT...UNTIL.
var

N : integer;

{ }

begin
N:=1;
repeat
Writeln(N);
N:= N+1;
until N>10
end.


;
. . ,
, . ,
, .
;
. , ?
N ,
. ?
, ,
!
.
:
, .
-, :
N:= _ _
, :
FOR N:= _ TO _ DO
, : FOR, TO, DO.
FOR
. TO , DO
. ? ,
!
.
112

17

var

N : integer;

{ }

begin
for N:=1 to 10 do Writeln(N);
end.

. , ,
REPEAT. FOR,
, .
,
, .
, .
, !
:
? DO . ,
, BEGIN...END, . ,
,
.
{ P_17_1 , }
var

A, B, C : integer; { }
Q, E : integer;

{ }

S: string;
begin
Randomize;
E:= 0; { }
for Q:= 1 to 15 do begin
A:= 1+ Random(10);

{ 15 }
B:= 1+ Random(10);

Write(Q,) , A, x ,B, ? );
Readln(C);
{ , }
if A*B <> C then E:= E+1;
end;

{ }

case E of

{ }

0:

S:=!;

1,2:

S:=;

3..5: S:=;
else

S:= !;

end;
Writeln(S,

Enter); Readln;

end.

113

17

.
Write(Q,) , A, x ,B, ? );

Q.
CASE.
, , (1, 2),
CASE .
. ,
. ,
(), .
(35) .

FORTODO ,
( ) .
,
, .
CASEOFELSEEND
, .

?
) .
.
.
) ,
, (1-5) (6,7),
:
= 2

= 7

= 20
!

.
) , , N, 1
N , :
114

17

N = 3
3
2
1

) FOR...,
, , :

FOR N:= _ DOWNTO _ DO


DOWNTO (DOWN );
,
, .
( ).

115

18
,
: .
, , .
: PASCAL
P
A
S
C
A
L

, ,
.


, , ,
. ,
? .
, . , ,
, . ,
, .
.
, !

? , 14 ,
, , 17.

CHAR, . , ,
.
.
var c1, c2, c3 : char;

,
, .

116

18
,
c1:= A;

c2:= B;

c3:= c1;

, , . ,
, ,
! ,
.
c1:=ABBA;

{ }

c2:=;

{ ! }

,
.
var

c1 : char;

S: string;

. . .
S:= c1;

, 255 !
,
, .
c1:= A;

c2:= B;

c3:= A;

S:= c1 + c2 + B + c3;

{ ABBA }

S:= pascal+ c1 + S;

{ }

, Readln,
Write Writeln, :
Readln(c1);
Writeln(c1);

, ,

. , .
, , .
, . ,
PASCAL P , L .
,
, .
,
. ,
. , 3- .
117

18
,
c1:= S[3];

. ,
, , .
c1:= S[2*N+1];

N , c1
S.


,
, . ?
, , .
?
, , ,
, . Length .
, , .
K:= Length(S);

K
S. ( ).
S:= ;

K:= Length(S);

{ =0 }

S:= PAS

K:= Length(S);

{ =3 }

K:= Length(S+CAL);

{ =6 }

K:= Length(, !);

{ =17 }


,
.
.

118

18
,
{ P_18_1 }
var

S: string;
C: char;
k, L : integer;

begin
repeat
Write( : );
L:= Length(S);

Readln(S);

{ }

for k:=1 to L do begin


C:= S[k];

{ }

Writeln(C); { }
end;
until L=0;

{ L=0, }

end.

, ,
, . ,
; L ,
.
,
.
, .
{ P_18_2 , }
var

S: string;

k : integer;

begin
repeat
Write( : );
for k:=1 to

Length(S)

Readln(S);

do Writeln(S[k]);

until Length(S)=0;
end.

Length FOR,
Writeln S[k]. FOR
, BEGINEND.
UNTIL,
Length.
. ,
.

119

18
,

.

CHAR.
CHAR
, .
.
, ;
.
,
.
.
length.

FOR.

?
A)
. ?
) , .
:
S[i]:=
) S ?
for i:=1 to Length(S) do S:= S + S[i];
for i:=Length(S) downto 1 do S:= S + S[i];
for i:=1 to Length(S) do S:= S[i] + '-';

.
)
(, , ), - . :
8 (123) 45-67-89. , .
, , .
, :
8123456789.

120

19
:

, ,
! ? ,
, .
:
! ?
,
.
: ,
.
, .
, .
, . ,
-, .
, !
15- ,
, .
, - (,
Writeln, Readln, Length, Random). ,
? ? - ! ,
. , ,
, ?
, . , !


.
Enter
.
Write( Enter);

Readln;

, . ,
, .
, .
PROCEDURE,
, .
, .

121

19
:

Pause (),
(. 40).

Procedure Pause;

Begin

Write( Enter);
Readln;
End;

. 40 Pause

. ,
BEGINEND.
. BEGINEND
, .
, BEGINEND !
, !
, ? . 41
.
,
BEGIN END.
const . . .

var

. . .

Begin
. . .

End.

. 41

, ,
. ,
122

19
:

, .
Pause ,
.
{ P_19_1 }
var Man : string;
procedure Pause; {--- ---}
begin
Write( Enter);
Readln;
end;
begin

{--- ---}
Writeln( ?); Readln(Man);
Writeln(, , Man);
Pause;

{ }

end.

, ?
, ,
. ,
?
! , .
.
Pause, .
. 42 (
). Pause ,
, .

, .

123

19
:

Pause

1) begin
6) begin

2) Writeln( ?);

7) Write( Enter);

3) Readln(Man);

8) Readln;

4) Writeln(, , Man);

9) end;

5) Pause;
10) end;

. 42

, , ,
, .
, .
,
Enter, .
begin

{--- ---}
Writeln( ?); Readln(Man);
Writeln(, , Man);
Pause;
Pause;
Pause;

end.


?
. .
. ,
, .
Pause ( Enter!);

, ?
, .
?
, .
124

19
:

; .
, , .
procedure Pause (msg : string);

msg (
message ). ,
, . , ,
, ,
, . , ,
.
procedure Pause (msg : string);

{ }

begin
Write(msg);

Readln;

end;

?
msg
, . :
,
. .
{ P_19_2 }
var Man : string;
{--- msg ---}
procedure Pause (msg : string);
begin
Write(msg);

Readln;

end;
begin

{--- ---}
Writeln( ?); Readln(Man);
Writeln(, , Man);
Pause( Enter);
Pause( );
Pause( !);

end.

Pause
, .

125

19
:

.
, .
( ),
, .

.
, .

, .

?
) Pause,
, .
.
Pause(true);

{ Enter }

Pause(false);

{ Press Enter }

) ( Line ),
, , .
Line(3);

{ *** }

Line(7);

{ ******* }

: .

126

20
:
. , ?
( )
,
. ?
, .
. ?
, ,
.
: , ,
( , ?).
A ( ) B.
, ABBA,
BBBB.


. 43
. , ,
, .
, . ?
, ,
, ,
, (. 44).
,
, Scan.
.

127

20
:

= 1

A?
= 1

= 3?

. 43 -

128

20
:

procedure Scan(arg)
= 1

A?

= 1


Scan(S)

= 3 ?

. 44 - () ()

, - ,
.


, ?
? ! , ,
.
, ,
.
. ,
.
.
, .
,
. ? . ,
Scan , .

129

20
:
{ P_20_1 }
var S: string; k: integer;
begin

{--- ---}
for k:=1 to 3 do begin
Write( : ); Readln(S);
{

Scan(S);

Writeln(S);
end;
end.

,
Scan(S), .
, ,
, ! ,
, -.
,
. :
, .
.
Scan(S),
.
{ P_20_1 }
var S: string;

k: integer;

{--- ---}
procedure Scan(arg : string);
begin
end;
begin

{--- ---}
for k:=1 to 3 do begin
Write( : ); Readln(S);
Scan(S);
Writeln(S);
end;

end.

Scan arg (
argument ).
. ,
Scan(S), ,
130

20
:

, S
arg.
,
Scan. ,
A B.
.
for k:=1 to Length(arg) do
if arg[k]=A then arg[k]:=B;

, arg , k .
Scan, .
{ P_20_1

var S: string;

k: integer;

procedure Scan(arg : string);


begin
for k:=1 to Length(arg) do
if arg[k]=A then arg[k]:=B;
end;
begin

{--- ---}
for k:=1 to 3 do begin
Write( : ); Readln(S);
Scan(S);
Writeln(S);
end;

end.

k.
: .
, ? ? .
Delphi. Delphi
k , , .


. ,
. ,
! -, A B. ,
. , ,
131

20
:

, .
, !
, , ,
. ,
. ,
k, , .
k , .
, .
?
. ,
.


. ,
,
, ,
. , ,
, , .
.
.
const c1 = ;
procedure Local;
begin
Writeln(c1);
end.
begin

{--- ---}
Local;
Writeln(c1);
Readln;

end.

, C1, ,
. C1,
Local .
, .

132

20
:
const c1 = ;
procedure Local;
const c1 = ;
begin
Writeln(c1);
end.
begin

{--- ---}
Local;
Writeln(c1);
Readln;

end.

, ,
. C1 ,
, .
, ,
,
. ,
, ,
. :
(, )
, ;


).

, .
{ P_20_1 }
var S: string;

k: integer; { }

procedure Scan(arg : string);


var k: integer; { }
begin
for k:=1 to Length(arg) do
if arg[k]=A then arg[k]:=B;
end;

133

20
:
begin { }
for k:=1 to 3 do begin
Write( : ); Readln(S);
Scan(S);
Writeln(S);
end;
end.

, k ,
, .
! ,
.

!
,
.
-, .
, ,
. ,
?
. ,
().
, .
.
.
.


, .
- QAAAW. ,
QBBBW ( A B).
? , , ,
.

,
.
, ,
, .

134

20
:

(, )
, .
,
,
.
,
.

135

21

,
P_20_1. ?
. , , !
, ,
. , IDE
, .
. , ,
.

,
.
, .
,
. , -!
: Run
Debug ( ).
Run
(. 45).

Ctrl+F9

F8

F7

F4

Ctrl+F2

. 45 RUN

136

21

. 1 .
. 1 Run

Run

Trace into

Step over

Go to cursor

Program Reset

Parameters...

Ctrl+F9

F7

().
,
,

.

F8

.
,
, .

F4

,
, .

!

Ctrl+F2

.
,
.

,

.

:
, , .
, , , .
, ,
. ,
.
Debug (. 46),
, ,
.
(User screen) (Output).
.

137

21


( )

Alt+F5
( )
Ctrl+F4

Ctrl+F7


(Ctrl+F8)

. 46 Debug

, ?
, , P_20_1.
.
Watches.
k Ctrl+F7.
(. 47).

. 47

k ,
. OK,
(. 48). Watch expression ,
, , , .
OK. ,
(. 48).

138

21

. 48 Watches

,
Unknown value . .
, Watches.
.
, Window Tile ( )
. 49.

()

. 49 Window Tile


, (. 50).
, .
,
. Ctrl+F9,
F7 ( Trace).
, .
F7
, .
F7 , Readln,
.
QAAAW Enter,
Scan, . 50.

139

21

. 50 Scan

Watches. k
, k,
. S ,
. arg ,
Unknown value.
F7 ,
Scan. arg ,
S, .
F7, END
. , arg
QBBBW, , .
(. 51).

. 51 Scan

140

21

k , .
, k, k
. S ( ) -
, .
F7 ,
, Scan
(. 52).

. 52 Scan

, ? ,
(. 50), , .
k , ,
. , S,
. ?
.
Scan S
arg, . ,
, .
S ! - !


Scan.
procedure Scan(arg : string);

arg
,
141

21

.
. , ,
VAR.
procedure Scan(var arg : string);

. arg
, . ?
.
arg
S. , arg,
S, .
,
Ctrl+F2.
.
Scan, , arg S
(. 53). , , !

. 53

,
Ctrl+F9.

.
,
.

142

21

VAR,
.
.
, ,
VAR.
.

?
) Ctrl+F8
. .
Scan ( END)
(Ctrl+F9). ? , , ?
) Scan
Go to cursor ( F4).

143

22

.
?
, !
, , ,
. .


. ,
A B, .
T:= A;

{ A }

A:= B;
B:= T;

{ B , A }

T .
, Swap .
Swap , , .
, .
.
,
procedure Swap (x: integer; y: integer);

,
. .
procedure Swap (var x: integer; var y: integer);

,
, .
procedure Swap (var x, y: integer);

,
VAR.
Swap P_22_1 .

144

22

{ P_22_1 }
{ }
procedure SWAP(var x,y : integer);
var t: integer;
begin
t:= x;

x:= y;

y:= t;

end;
var A, B : integer;
begin

{--- ---}
A:= 10; B:= 20;
Writeln(A= , A, B= , B);
SWAP(A, B);
Writeln(A= , A, B= , B);
Readln;

end.

? !


P_20_1. Scan
, A B.
? !
, , .
procedure Scan(var arg: string; Ch1, Ch2: char);
var k: integer;
begin
for k:=1 to Length(arg) do
if arg[k]= Ch1 then arg[k]:= Ch2;
end;

Ch1 Ch2 , .
, .
. ,
.
( 1 2).
Scan(S, 1, 2);

:
145

22

Scan(S, 1);

{ }

Scan(1, S, 2);

{ }

Scan(S, 1, 2, 3);

{ }

Scan(S, 1, 2);

{ }


.
-, Readln Writeln,
.
P_20_1 ,
, .


. ,
Calc .
procedure Calc(arg: string; Ch: char; var Res: integer);
var k: integer;
begin
Res:=0;
for k:=1 to Length(arg) do
if arg[k]= Ch1 then Res:= Res+1;
end;

: arg, Ch
Res .
. : , ,
arg .
, 255 ,
256 ! Calc 256
arg, .
arg , ,
. ,
4 ! ,
.
procedure Calc(var arg: string; Ch: char; var Res: integer);

, ,
, .

146

22

Calc(PASCAL, L, Result);

,
. , VAR
, . ?
? , : VAR
CONST, .
procedure Calc(const arg: string; Ch1: char; var Res: integer);

, .
Calc(PASCAL, L, Result);

{ }

Calc(S, L, Result);

{ }

CONST
. ,
, .

.
,

.


CONST VAR.
,
CONST, VAR.

, CONST VAR .

?
) P_22_1 .
) P_20_1 ,
Scan .
) Calc,
.

147

23

-,
. , ,
. - , ,
? , .
, , . ,
, .
, .
, ,
.
Random Length, , , .
x:= 1+ Random(10);

{ }

Writeln(Length(S));

{ S };


, .
.


,
. , ,
.
function _ : ;

{ }

function _ () : ;

{ }

. -,
PROCEDURE FUNCTION. -,
( ), .


. ,
. ,
, . ,
.

148

23

function Max(arg1, arg2 : integer) : integer;

, , . Max
, MAXIMUM .
.
function Max(arg1, arg2 : integer) : integer;
begin
if arg1 > arg2
then Max:= arg1
else Max:= arg2
end;

Max, ?
! , ,
. , ,
, !
.
A:= Max( 20, 10 );

{ A = 20 }

Writeln( Max( A, B ) );

{ A B }


, , .
A:= Max ( Max( 20, 10 ), 40 );

{ A = 40 }

A:= Max ( Max( 20, 10 ), Max( 200, 100 ) );

{ A = 200 }

Max(20,10),
, Max(20,40),
.
, .
.
Max .



. ,
.
.
, , , Count .
149

23

function Count(const Str : string; Ch : char): integer;

: ,
. , CONST
, .
.
function Count(const str : string; ch: char): integer;
var N, i: integer;
begin
N:=0;

{ }

for i:=1 to Length(str) do


if str[i]=ch then N:= N+1;
Count:= N;

{ }

end;

N,
.
.
if str[i]=ch then Count:= Count+1; { - ! }

:
! ,
.
, , P_22_1 Count.
S,
BANAN. ,
. .
{ P_23_1 }
function Count(const str : string; ch: char): integer;
var N, i: integer;
begin
N:=0;

{ }

for i:=1 to Length(str) do


if str[i]=ch then N:= N+1;
Count:= N;

{ }

end;

150

23

var S: string;
begin {---

---}

S:='PASCAL';
Writeln( Count(S, 'A'));
Writeln( Count('BANAN', 'N') + Count('BANAN', 'B'));
Readln;
end.


P_20_1, A
B. , , ?
Scan ,
. , , .
, VAR CONST ,
arg
.
{ P_23_2 }
function Scan(arg : string): string;
var k: integer;
begin
for k:=1 to Length(arg) do
if arg[k]=A then arg[k]:=B;
end;

{ arg }

Scan:= arg;

var S: string;

k: integer;

begin {--- ---}


for k:=1 to 3 do begin
Write( : ); Readln(S);
Writeln(Scan(S));
end;
Readln;
end.


,
- .
, . Swap () ,
.
TRUE, .
151

23

, (
Swap, ). , .
function Swap( var a1, a2 : integer) : Boolean;
var t: integer;
begin
if a1 > a2
then begin
{ }
t:=a1; a1:=a2; a2:=t;
Swap:= true
end
else Swap:= false
end;

? : N1, N2, N3,


. ,
, N1 , N3
(N1 <= N2 <= N3).
Swap ( ).
Swap(N1, N2);

{ N1 <= N2 }

if Swap(N2, N3)

{ N2 <= N3 }

then Swap(N1, N2);

{ N1 <= N2 <= N3 }

:
, .

(Extended syntax), ,
.

Result
.
, Delphi , ,

Result. Result .
.

152

23

function Count(const str : string; ch: char): integer;


var i: integer;
begin
Result:=0;

{ }

for i:=1 to Length(str) do


if str[i]=ch then Result:= Result +1;
end;

, Result ,
, .
.
, , ,
, . ?
!

, .
.
,
, .

.
, .

Extended syntax.

?
) .
TRUE, , FALSE
. . ?
) .
,
. .
) ( ),
:
. : N
: if (N mod 2) = 0 then ...

153

24

, . !
. ,
, :
. , , ,
? , , ,
, , , .
, ;
.


.
,
, .
. ?

. . 54
. ,
.
.
!

...

...

. 54

? .
, ,
( ). ,
: .
,
. :
, .
, .
.
154

24


.
, . ,
. ( Crypt )
, .
, .
function Crypt (X: char): char;


. .
if X=
then Crypt:=
else if X=
then Crypt:=
else . . .

?
. 33 , ,
66. ,
, .
!
CASE?
.
case X of
: Crypt:=;
: Crypt:=;
. . .
end;

: CASE ,
, , .
, .
:
CASE, , , . ,
?


.
. ,
155

24

!
,
.
, ,
. ?
, , .
, . ?
. , ,
, , , .
,
. ,
, , .
:
.
, . ,
, .
256 0
255 . 256, 300 400?
, 256 ,
( ,
). , , ,
.
, ,
.
,
.
, .
ASCII American Standard Code for Information Interchange
.
.
, ( MS-DOS) .
.
0 31. ,
10 13,
.
32 127,
, .
,
32.

156

24

, ,
( ) .
,
.
:
(, , , ) !


, , .
. ,
.
, ?
. .
CHAR,
, , .
function Char(arg : integer) : char;

, CHAR.
, !
, . !
,
. ,
.
var n: integer;
begin
for n:=40 to 50 do
Writeln(n,'

', Char(n))

end.


ORD, .
ASCII,
.
function Ord(arg : char) : integer;

, .

157

24

var : char;
begin
for c:=A to F do
Writeln(c,'

', Ord(c))

end.

FOR .
, ,
.
, ,
.


Crypt,
.
function Crypt(arg: char): char;
begin
Crypt:= Char(Ord(arg) + CKey);
end;

CKey , -
. arg ,
, .
, .
255, !
Char? , 256.
, Char(260) 4 (260256).
? ! , 32 ( 0 31)
, ,
.
, Char, .
255, 32
, 32 255.
if X>255 then X:=X256+32;

{ }

158

24

function Crypt(arg: char): char;


var x: integer;
begin
x:= Ord(arg)+ CKey;
if x>255

then x:= x256+32;

Crypt:= Char(x);
end;


, .
,
. , ,
. EnCrypt.
function EnCrypt(arg: char): char;
var x: integer;
begin
x:= Ord(arg) CKey;
if x<32

then x:= x+25632;

EnCrypt:= Char(x);
end;


P_24_1.
{ P_24_1 }
const CKey = 2; { }
{ }
function Crypt(arg: char): char;
var x: integer;
begin
x:= Ord(arg)+ CKey;
if x>255

then x:= x256+32;

Crypt:= Char(x);
end;

159

24

{ }
function EnCrypt(arg: char): char;
var x: integer;
begin
x:= Ord(arg) CKey;
if x<32

then x:= x+25632;

EnCrypt:= Char(x);
end;
{ }
procedure CryptString(var arg: string);
var k: integer;
begin
for k:=1 to Length(arg) do
arg[k]:= Crypt(arg[k]);
end;
{ }
procedure EnCryptString(var arg: string);
var k: integer;
begin
for k:=1 to Length(arg) do
arg[k]:= EnCrypt(arg[k]);
end;
{ }
var

S: string;
Oper: integer;

begin
repeat
Write(' : '); Readln(S);
Writeln(' : 1 ,+
2 ,+
');
Readln(Oper);
case Oper of
1: CryptString(S);
2: EnCryptString(S);
else Break;
end;
Writeln(S);

{ }

until false;
end.

160

24

.
CKey, .
,
.
Crypt EnCrypt .
CryptString EnCryptString ,
VAR. , ,
(Oper).
, !
, , .
.
pascal , rcuecn.
rcuecn , .
: pascal
: 1 , 2 ,
: 1
rcuecn
: rcuecn
: 1 , 2 ,
: 2
pascal
: 1 , 2 ,
: 3

,
. , .
.

.
256, 32 (
0 31) ( 32 255).
Char.
Ord.
, FOR
, CASE
.

161

24

?
) ,
( ).
.
.
function CryptChar(arg: char; key: integer): char;
procedure CryptString(var arg: string; key: integer);

) , .
? ?

162

25

, .
.
.


, : ,
, . , - ,
. , (
). ,
, .
? -. ?
. ! ,
, .
, ,
.
, .
:
;
( ).
.
TXT (), BAT ( ), LOG ( ).
PAS .
MS-Word ( DOC) ,
. , ,

IDE, .


, .
? .
,
, :
1, 2, ,
3.

163

25

111
22
3

;
, .
49 49 49

13 10

50 50

13 10

13 10

51

13 10

49, 50 51 1, 2 3 (
ASCII), 13 10 ,
. ,
, ! ,
,
.
- ,
. 13 Carriage Return
CR. , ,
: ,
, .
10 Line Feed
, LF.
, .
: ,
CR LF.
, , .
, ,
. .

CR+LF, . ,

-,
.


,
. , .
? ,
! , .
Readln
Writeln. :
164

25

TEXT.
.
var F: Text;

F .
Readln (F, S);

{ S }

Writeln (F, );

? :
? !
,
?
, . :
1.
2.
3.
4.

.
.
, , .
.

.
, .


, F TEXT.
, ,
.
. Assign
, : ,
.
Assign(F, C:\AUTOEXEC.BAT);

,
. ,
. , ,
, . Assign ,
.
? ,
.

165

25

.
, Reset (
).
.
Reset(F);

Reset ,
. ,
, .

Readln , .
? Reset
: : File not found ,
.

( ). ,
Readln. ,
.
Readln(F, S);

S . :
S ,
.
? , ?
Readln ,
. ,
, .

, . Reset
.
Readln .
?
, Readln
. , .
EOF, End Of File
. EOF ,
TRUE, .

166

25

if Eof(F)
then { }
else { }

, EOF ( ,
); , .
? .
.
Close .
Close(F);

,
, ,
, .
, .
. 55 .

(Assign)


(Reset)

(Readln)

(Close)

. 55


, ,
, .
.
, (, )
.
,
Reset.

, .
, ,
.

167

25

{ P_25_1 }
var

F: text;

{ }

S: string;

{ }

begin
Assign(F, 'P_25_1.pas');

{ }

Reset(F);

{ }

repeat
if Eof(F) then Break;

{ , }

Readln(F, S);

{ }

Writeln(S);

{ }

until false;
Close(F);

{ }

Readln;

{ Enter }

end.

,
. !
, , ,
. . .
until Eof(F);


!
, .
, :
REPEATUNTIL;
FORTODO.
,
:
WHILE <> DO <>
- :
. DO ,
.
BEGINEND, .

168

25

WHILE

<>

DO

BEGIN

< >

END
.
{ P_25_2 }
var

F: text;

{ }

S: string;

{ }

begin
Assign(F, 'P_25_2.pas');

{ }

Reset(F);

{ }

while not Eof(F) do begin

{ }

Readln(F, S);

{ }

Writeln(S);

{ }

end;
Close(F);

{ }

Readln;

{ Enter }

end.

WHILE NOT (),


, .
.
. ,
, .

,
: CR ( )
LF ( ).
TEXT.
:
Assign
Reset.
Readln,
.
;
Readln .

169

25

,
. .
Eof,
TRUE, .
,
WHILE...DO.
Close.

?
) F
?
F := c:\autoexec.bat;

) ,
.
) ,
.
) , ,
. ?
, .
) - ( 16) ,
, .
.

170

26
, !
.
, .


, :
TEXT;

Assign;
Close.
, (. 56).

(Assign)

(Rewrite)


(Writeln)

(Close)

. 56

, ,
.
, Assign,
Rewrite .
Rewrite(F);

:
, . ,
. , ,
, . ,
!
. ?
Writeln. ?
, , .

171

26
, !
Writeln(F, S);

{ F TEXT, S }


. ,
,
( ).
Close.
,
, .
.


: ,
1 10, .
{ P_26_1 }
var

F: text;

{ }

k: integer;
begin
Assign(F, 'P_26_1.txt');

{ }

Rewrite(F);

{ }

for k:=1 to 10 do

{ 10 }

Writeln(F, k);
Close(F);

{ }

end.

? , . ?
P_26_1.TXT
. ,
.


, , : 1)
, 2) 3) .
: ,
, .
, .
, CRYPT.TXT,
. (
), ( ).
Z, .
172

26
, !

CRYPT.TXT

. 57

- (. 58).


(
)


Z
()


Z
()

-
:

. 58 - /

-, . 59. :
( ).

173

26
, !
-


CRYPT.TXT


CRYPT.TXT

Eof = FALSE

. 59 - -

. ,
? , .
P_24_1. ,
, .

174

26
, !
{ P_26_2 }
const CKey = 2; { }
{ }
function CryptChar(arg: char): char;
var x: integer;
begin
x:= Ord(arg)+ CKey;
if x>255 then x:= x-256+32;
CryptChar:= Char(x);
end;
{ }
function EnCryptChar(arg: char): char;
var x: integer;
begin
x:= Ord(arg)- CKey;
if x<32 then x:= x+256-32;
EnCryptChar:= Char(x);
end;
{ }
procedure CryptString(var arg: string);
var k: integer;
begin
for k:=1 to Length(arg) do arg[k]:= CryptChar(arg[k]);
end;
{ }
procedure EnCryptString(var arg: string);
var k: integer;
begin
for k:=1 to Length(arg) do

arg[k]:= EnCryptChar(arg[k]);

end;
{----- - -----}
procedure

CryptFile(const aFile: string; aOper: boolean);

const CFixName='CRYPT.TXT';
var

FileIn:

text;

FileOut: text;
S:

{ }

{ }
{ }

string;

175

26
, !
begin
if aOper then begin

{ }

Assign(FileIn, aFile);
Assign(FileOut, CFixName);
end else begin

{ }

Assign(FileIn, CFixName);
Assign(FileOut, aFile);
end;
Reset(FileIn);

{ }

Rewrite(FileOut); { }
while not Eof(FileIn) do begin
{ }
Readln(FileIn, S);

{ }

if aOper
then CryptString(S)

{ }

else EnCryptString(S); { }
Writeln(FileOut, S);

{ }

end;
{ }
Close(FileIn);
Close(FileOut);
end;
{----- -----}
var

S: string;
Oper: boolean;

{ TRUE , FALSE }

begin
Write(' (1 , ):');
Readln(S);
Oper:= S='1';

{ Oper=TRUE S='1' }

if Oper
then Write(' : ')
else Write(' : ');
Readln(S);
{ - }
CryptFile(S, Oper);
end.

, .
Oper.
,
S. TRUE ,
176

26
, !

. S .
, CryptFile
.
,
( ).
}"Rtqi2420rcu"
xct"Ocp"<"uvtkpi=
}///"""///
rtqegfwtg"Rcwug=
dgikp
"""""Ytkvgnp*)"Gpvgt<)+=""Tgcfnp=

, ! ,
, .
.
,
. , -
. , ( )
.
. ,
! .

, ,
TEXT.
:
Assign
Rewrite.
Rewrite ,
.
Writeln,
.
,
.
Close,
.

177

26
, !

?
) , ,
, .
.
) .

, .
:
,
.
,
.

:
1
,
2
.
3
,
4
.

178

27
!
, !
, .
, .
Free Pascal.
. ,
.


? !
, .
,
, .
? F9,
. ,
. ,
, .
: , . ! !
,
Runtime errors.


, ,
.
var

X : integer;

begin
Readln(X);
Writeln(100 div X);
end.

100 X.
. ,
.
Runtime error 200, . - ,
, .
? ,
. , , .

179

27
!
var

X : integer;

begin
Readln(X);
if X<>0
then Writeln(100 div X)
else Writeln( , !);
end.

, ,
. .


, ,
.
/ (- I/O Error), .
? , , .
, - . ?
. ,
, .
,
. ,
: , .
.
/.


,
Options Compiler (. 60),
(. 61).

. 60

180

27
!

. 61

Generation code
Code generation. I/O checking
- (I/O Input/Output /).
EXE- ,
- .
, ,
. , , ! ?

-
, .
IOResult,
, - .
, ,
. :
-.
.
, ,
( FileName).
Assign(F, FileName);
Reset(F);
if IOResult=0
then Writeln ( + FileName)
else Writeln ( +FileName+ !);


I/O checking, . ,
181

27
!

,
.
. ,
- : -
, - ?
, . ?


, ,
. ,
- . ,
, , .
, ,
.
? $
,
. , ,
.
, , -,
.
{ $I+

- - }

{ $I-

- - }

.
.

!
. ,
, $I.
TRUE, ,
, . ,
.

182

27
!
{ P_27_1 }
function FileExists(const aName: string): boolean;
var F: text;
begin
FileExists:= false;

{ , }

Assign(F, aName);
{$I-} Reset(F); {$I+} { Reset }
if IOResult=0 then begin
{ }
Close(F);

{ }

FileExists:= true;
end;
end;
begin

{--- ---}
Writeln( FileExists('AUTO.BAT') );
Writeln( FileExists('C:\AUTOEXEC.BAT') );

{ false }
{ true }

end.

,
Reset .
-, . ,
Reset
.
, ,
.
? ,
IOResult. , , ,
,
FileExists . ,
!


, , ,
.
, EXE-
.
. , ,
. ,
(. 61)
, , .
Ctrl+O+O. ,
183

27
!

CTRL, O. , !
, , .
{$IFDEF NORMAL}
{$H-,I+,OBJECTCHECKS-,Q-,R-,S-}
{$ENDIF NORMAL}
{$IFDEF DEBUG}
{$H-,I+,OBJECTCHECKS-,Q+,R+,S-}
{$ENDIF DEBUG}
{$IFDEF RELEASE}
{$H-,I-,OBJECTCHECKS-,Q-,R-,S-}
{$ENDIF RELEASE}

.
(Normal/Debug/Release) Options Mode.

. $IFDEF
( 60).
, , .
{$H-, I+, OBJECTCHECKS-, Q-, R-, S-}

? :
.
.


().

.
, .
,
.
, .

. ,
.
: ,
.
()
.
184

27
!

?
) , IOResult
.
.
) ,
, .

185

28

, ,
, , . ,
. , .
, , , ,
. , IDE
, .
IDE:
. . 90- 20-
Borland .
! , ,
, ? .


Borland,
Borland Pascal MS-Windows.
. ,
.
, , ,
.
MS-Windows:
, . ,
. IDE
Window (. 62).
.
.
Next Previous
. F6 Sift+F6
.
, (
).

186

28

/
/

. 62 Window

,
. , F9 ,
, , .
!
.
Window List ( Ctrl+0). ,
(. 63).

. 63

OK.
Size/Move .
,
.

187

28


, ?
. ,
? (
Copy Paste ). ,
( , ?).
,
.
. :
( );
(Ctrl+Insert);
, (
);
(Shift+Insert).
.
, .
. Shift,
( ,
). :
, .
, ,
, Ctrl+H.
, MS-Windows
. , : IDE
MS-Windows , . ,
MS-Windows IDE .
, IDE Edit
Show Clipboard.


,
. :
?
, ! ,
? , .
Help F1 , !
- , , .

188

28

, .
( ), ,
IOResult. Ctrl+F1.
, Help (. 64).

. 64 IOResult

?
.
.
. .
.
, Enter.
. . 65
Close.
,
. ( Enter),
, .

189

28

. 65 Close

C ,
: , .
! - ?
,
(Ctrl+Insert, Shift+Insert).
, IDE Free Pascal
4. , Borland Pascal, :
.
, BP.EXE
TURBO.TPH.
,
?

, .
;
, MS-Windows.
.
IDE.

190

29
-
, .
, , .
.

, 1

, .
.
.
: ,
. ,
, .
, ,
.
, .
( ), ?
, . , !
, ,
. ,
, . ,
, .
.
,
. , ,
. ,
.
, .
123
325
234

, ,
IDE. : ,

Police.txt. ,
.

191

29
-

, !
, , .
, , .
,
, .
.
, P_29_1.
.
, : ,
, . ,
TRUE. ,
-. , , ,
, , .

192

29
-
{ P_29_1 , 1 }
function FindNumber(var aFile: text; aNumber: integer): boolean;
var N: integer;

{ }

begin
FindNumber:= false;

{ ,

Reset(aFile);

{ }

N:=0;

{ }

{ , }
while not Eof(aFile) and (N<>aNumber) do begin
Readln(aFile, N);
FindNumber:= (N=aNumber);

{ true, }

end;
end;
var

F: text;

Num: integer;

begin {----- -----}


Assign(F, 'Police.txt');
repeat
Write(' : ');

Readln(Num);

if FindNumber(F, Num)
then Writeln(' , !')
else Writeln(' ');
until Num=0;

{ 0 }

Close(F);
end.

.
F Police.txt.
REPEATUNTIL .
FindNumber (Find ,
Number ). ,
.
( VAR).
! ,
:
! , aFile
F.
a (aFile, aNumber)?
? , , ,
. ,
. ,
193

29
-

.
.
, ()
a ( argument).
.
FindNumber.
FALSE. ,
. ,
, WHILE .
Reset
. ,
. Reset
.
, !
WHILE, ,
.
while not Eof(aFile) and (N<>aNumber)


. ,
, .
.
FindNumber:= (N=aNumber);

{ true, }

, ( )
. ,
TRUE, . ,
.
.
if N=aNumber
then FindNumber:= true
else FindNumber:= false;

, , .
, ,
.

194

29
-

, 2
Police.txt.
, ,
, .
123 234 325
223 240
845 431 205

,
, . , ,
.
Police.txt
. ?
, .
, ,
, 123, 223 845.
, . ?
Readln.
, . .
(. 66).
Eoln (
13 10).
Reset

123

234

325

Readln

223

240

Eoln

Readln

845

431

205

Eoln

Eoln

. 66 Readln

, Reset .
Readln . ,
, , , .
, , Readln
, ,
. ! LN
195

29
-

( Line ). , Readln
, ?
, , !
Read ( ),
.
. !
Read . 67.
Read

Read

Reset

Read

123

234

325

223

240

Eoln

845

431

205

Eoln

Eoln

. 67 Read


.
, . ?
,
.
, ,
,
Readln(aFile, N);


Read(aFile, N);

, P_29_2
, .
: ,
Read? , , Readln
, .
196

29
-

.
,
Reset.
Readln
.
.
Read
.
.

?
)
Police.txt ( ) (
). ?
)
, ? .

197

30

?
?
. !.. ,
!
. , ,
. , ,
. ? .
-
. ?
. , ,
.
. ,
. ,
.
,
. ,
. , .

3 5 4

5 5 5 5

4 5 5 4

3 4 3

4 3

12

4.0

20

5.0

18

4.5

10

3.3

3.5

,
,
.

198

30

, :
. ? ,
! , !


:
, :
, . , ,
. ,
(
). .
3 5 4
5 5 5 5
4 5 5 4
3 4 3
4 3

12

4,0

20

5,0

18

4,5

10

3,3

3,5

, - .
. 68 . ,
, : ,
.

199

30

= 0
,


while

. 68

.
, .
. ,
, ,
.
,
.
( 29). , .
, ,
, !
, .
?
, , !
EoLn ( End of Line,
). .

200

30

function Eoln(var aFile: text): boolean;


TRUE, .
Eof, .
.
{----- Eoln -----}
var F: text;

N: integer;

begin
Assign(F, 'Police.txt');

Reset(F);

while not Eof(F) do begin


Read(F, N); { }
Writeln(N, '--', Eoln(F)); { }
end;
Close(F);

Readln;

end.

Police.txt ,
, . , Police.txt
.
1 2 3
10 20 30
100 200 300

.
1--FALSE
2--FALSE
3--TRUE
10--FALSE
20--FALSE
30--TRUE
100--FALSE
200--FALSE
300--TRUE

, TRUE
.
, ,
(. 69).
201

30

= 0,
= 0

while not Eoln

,
,


?

. 69 -

,
. , ,
, .
, .
, , ,
, .
REPEATUNTIL?
. ,
, , ! WHILE
.


P_30_1,
. :
,
.
HandleString, .
(
202

30

). ,
, .
, .
HandleString. ,
: Handle , String .
,
. .
Rating:= Sum div Cnt;

,
, .
, , ,
.
?
. , .
{ P_30_1 , }
{----- -----}
var

InFile, OutFile : text; { }


Counter: integer;

{ }

{----- -----}
procedure HandleString;
var

: integer;

{ , }

Cnt: integer;

{ }

Sum: integer;

{ }

Rating: integer;

{ }

begin
Sum:=0; Cnt:=0; { }
while not Eoln(InFile) do begin

{ }

Read(InFile, N);

{ N }

Sum:= Sum+N;

{ }

Cnt:= Cnt+1;

{ }

end;

203

30

if Cnt>0
then begin

{ }

Rating:= Sum div Cnt;


Writeln(OutFile, Counter, Cnt, Sum, Rating);
end
else

{ }
Writeln(OutFile, Counter, '

');

end;
{----- -----}
begin
Counter:= 0;

{ }

{ }
Assign(InFile,'P_30_1.in');

Reset(InFile);

{ }
Assign(OutFile,'

P_30_1.out');

Rewrite(OutFile);

{ "" }
Writeln(OutFile, '
Writeln(OutFile, '

');

');

{ ... }
while not Eof(InFile) do begin
Counter:= Counter+1;

{ }

HandleString;

{ }

end;
{ }
Close(InFile);

Close(OutFile);

end.

,
( ). P_30_1.in ,
, . ? -, .
, !
.
.



F7. ,
. Watch
Counter.

204

30

HandleString
.
, . -, ,
while not Eoln(InFile)

, .
:
.
while not Eof(InFile)

, - ,
, , .
, !
. , -
, .
, Ctrl+F2.
, ?
.
Eoln:
TRUE. ,
while not Eoln(InFile) , .
, !
,
, . ,
, .
,
, .
Readln, . ,
? ! ?
HandleString,
. .
while not Eof(InFile) do begin
Counter:= Counter+1;

{ }

HandleString;

{ }

Readln(InFile);

{ }

end;

Readln InFile,
. ,
205

30

. .
, .


, ,
.
P_30_1.out. , IDE: F3
. .

13124
24205
34184
43103
5273

? .
! ?
: :
1, 2, 3 . : 3, 4, 4, 3, 2. ,
, , ,
. ? , , .
Writeln(OutFile, Counter, Cnt, Sum, Rating);

, , ,
. , , .
Writeln(OutFile, Counter,

,Cnt,

,Sum,

, Rating);

,
, .
. ,
.


.
, .
,
, .

206

30

W := 15;
Writeln(OutFile, Cnt : 10, Sum : W);

Cnt 10
, Sum 15 (
W).
,
. ,
, ,
. ,
, :
, .
.
.
Writeln(OutFile, Counter:3, Cnt:13, Sum:14, Rating:12);

, .
Writeln(OutFile, Counter:3, '

');

. ,
P_30_1.out,
IDE ,
. -, IDE
, Yes
P_30_1.out. .

12

20

18

10

. ,
. .

207

30


, .
Rating:= Sum div Cnt;

,
. ? , .
, , .
, , .
7 div 3 = 2
7 div 4 = 1
7 div 5 = 1

, .
. ,
, .
.
. REAL, ,
.
.
REAL,
Rating :
var Rating: Real;

.
Rating:= Sum div Cnt;

, . , DIV (
Division ) ,
. ,
, /. ,
.
Rating:= Sum / Cnt;

! ,
, .

208

30

12 4.00000000000000E+0000

20 5.00000000000000E+0000

18 4.50000000000000E+0000

10 3.33333333333212E+0000

7 3.50000000000000E+0000

? ,
: - ! , ,
,
E , , .
, .
,
. ( ,
), .
Rating 12
, .
Writeln(OutFile, Counter:3, Cnt:13, Sum:14, Rating:12:1);

12

4.0

20

5.0

18

4.5

10

3.3

3.5

! ,
! .

Eoln .
WHILE.

Readln, .

. .
209

30

.
, , Real.
/
( ). DIV .
.

?
) .
.
) , .
var N: integer;
begin
for N:=1 to 20 do Writeln ( :N, N);
end.

.
) ,
( ).

210

31


.
, ,
. , .
, , .
Readln, ,
, , (
!).



: , !. ,
, . ,
. ,
! Read, .
var sym : char;
. . .
Read(InFile, sym);

{ }

S , .
S:= S + sym;

, ,
, .
, . 70.

211

31

while

. 70


, ! (
) ( ,
). ? .
Read ,
. -:
, . ,

( ). -
(. 71).

212

31

Repeat
?

while

. 71


P_31_1
P_30_1. , , .
? .
,
( ).
Assign(InFile,'Jurnal2.in');

Reset(InFile);

Assign(OutFile,'Jurnal2.out');

Rewrite(OutFile);

, Jurnal2.in
, 30- .

213

31

HandleString.
, Fam,
.
Fam:= ReadFam; { }

, .
Writeln(OutFile, Counter:3, Fam:18, Cnt:8,

Sum:14, Rating:11:1);

, ReadFam? ,
(. 71).
.
function ReadFam: string;
var sym: char;
s : string;

{ }
{ }

begin
s:=''; { }
{ }
repeat Read(InFile, sym); until Ord(sym)>32;
{ }
while not Eoln(InFile) and (Ord(sym)>32) do begin
s:= s+sym;
Read(InFile, sym);
end;
ReadFam:= s;

{ }

end;

.
.
sym <>

.
( 32), .

, , .
Jurnal2.out? , .

214

31

12

4.0

20

5.0

18

4.5

10
2

3.3
7

3.5

, .
. ,
. ,
, .
while Length(Fam) < 12 do Fam:= Fam + Char(32);

.
.
{ P_31_1 , }
var

InFile, OutFile : text; { }


Counter: integer;

{ }

{----- -----}
function ReadFam: string;
var sym: char;
s : string;
begin
s:=''; { }
{ }
repeat Read(InFile, sym); until Ord(sym)>32;
{ }
while not Eoln(InFile) and (Ord(sym)>32) do begin
s:= s+sym;
Read(InFile, sym);
end;
ReadFam:= s;
end;

215

31

{----- -----}
procedure HandleString;
var

: integer;

{ , }

Cnt: integer;

{ }

Sum: integer;

{ }

Rating: Real;

{ }

Fam: string;

{ }

begin
Fam:= ReadFam; { }
{ }
while Length(Fam) < 12 do Fam:= Fam + ' ';
Sum:=0; Cnt:=0;

{ }

While not Eoln(InFile) do begin

{ }

Read(InFile, N); { N }
Sum:= Sum+N;

{ }

Cnt:= Cnt+1;

{ }

end;
if Cnt>0
then begin

{ }

Rating:= Sum / Cnt;

{ . }

Writeln(OutFile, Counter:3, Fam:18, Cnt:8,


Sum:14, Rating:11:1);
end
else

{ }
Writeln(OutFile, '

');

end;
begin

{--- ---}
Counter:= 0;

{ }

{ }
Assign(InFile,'Jurnal2.in'); Reset(InFile);
{ }
Assign(OutFile,'Jurnal2.out');

Rewrite(OutFile);

{ "" }
Writeln(OutFile, '

Writeln(OutFile, '

216

');
');

31

{ ... }
while not Eof(InFile) do begin
Counter:= Counter+1;

{ }

HandleString;

{ }

{ }
if not Eof(InFile) do Readln(InFile);
end;
{ }
Close(InFile);

Close(OutFile);

end.

Readln
( ), Read ( ).
Read,
.
,
Write.
, .
Writeln.

?
)
Police.txt ( ) (
).

217

32

: .
, . ?
? , ,
: . ,
: , ,
.
( )
. ,
. , ,
.
, .

:
, ,
- . ,
, , ,
.
. 72 , .
: , .

String.
? ,
? , .
, . ,
, .
.
? ? ,
. ,
.

218

32

ShortInt, Byte

Integer, Word

Longint

Real

Single

Double

Extended

. 72

,
, . 72, .
, .
(
). ,
, .

219

32


.
Integer, ?
: Byte ShortInt.
, ,
. 256 0 255 .
, (BYTE).
, . ,
.
? , !
, Byte. Byte
.
var A, B, C : byte;

0 255. ,
,
.
- , ShortInt.
Short Integer . ?
, ,
128 127. 256 .
. ,
, ?
, , .
- ShortInt.
, :
.
:
Integer Word. .
Integer 32768 32767 (
Borland Pascal), Word
0 65535. , Word
. 16- ,
.
,
LongInt (Long Integer ).
, . . 2
, .

220

32

.
. , 32- Delphi
Free Pascal Integer LongInt .
. 2 ( Borland Pascal)

Byte

255

Shortint

-128

127

Word

65535

Integer

-32768

32767

Longint

-2147483648

2147483647

, LongInt ? ? ,
. ,
. . ,
, ,
.
.

,
, ,
, .
? : ,
, .
? , , ,
.
{$R+

- }

var

N : byte;

begin
N:= 255;

{ 255 }

N:= N+1;
Writeln(N); Readln;
end.

.
,
. Range checking
(. 73).
221

32

$R

$Q

. 73

, Runtime Error 201.


, ,
.
, (
).
{$R-

- }

,
! !
, !
,
, 5, 4.
(- OVERFLOW).
, .
{$R-

- }

var

N : byte;

begin
N:= 0;

{ 0 }

N:= N-1;
Writeln(N); Readln;
end.

: 255! ,
, !
, .
222

32

, ,
. ,
32767 INTEGER
-32768. :

. :
. . 74 .
Minimum = Maximum + 1
()

Minimum

Maximum

Maximum = Minimum 1
()

. 74

!
, ,
.
:
,
.
, :
, Longint,
,
, .
{ $R- }
var

B: Byte;

S: ShortInt;

W: Word;

N: Integer;

. . .
N:= B + S + W;

,
N !
, $R+.
223

32


, ?
! .
. ,
, .
procedure Inc (var N : longint);

{ N }

procedure Dec (var N : longint);

{ N }

N LONGINT,
, , WORD
INTEGER.
var

B: byte; N: integer;
. . .
Inc(B);

{ B:= B+1 }

Dec(N);

{ N:= N-1 }


, N:=N+1 N:=N-1.
IDE Borland Pascal? ,
$R+. ,
.

$R+ ,
. .
, M
. , 1
12. ,
, .
var

M : 1..12;

:
, . ,
$R+, ,
112.
( ).

224

32

.
var

M : 1..12;

{ }

D : 1..7;

{ }

M:= D;

{ }

: M , D
. ,
. ,
. .
, ? .

.

, . ,
M1 M2 ,
D1 D2 .
var

M1, M2 : (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec);
D1, D2 : (Mond, Tues, Wedn, Thur, Frid, Satu, Sund);


, .
M1:= Apr;

{ }

M1:= M2;

{ }

M1:= 3;

{ }

M1:= Jan+2;

{ }

D2:= M1;

{ }

, .
.
var

B : ( FALSE, TRUE );

{ B : Boolean; }

! Jan
Jan . , Write(M1)
, M1.
, ? TRUE
FALSE. , .
225

32


, ,
.
, ,
. .

,
. ,
. ? ,
.
, ? ,
. ,
0, 1, 2 ,
0...11. , Jan
, Feb .
: FALSE , TRUE .
,
. Ord ( Order ),
( ).
Writeln ( Ord(5) );

{ 5 }

Writeln ( Ord(F) );

{ 70 }

Writeln ( Ord(Mar) );

{ 2 }

Writeln ( Ord(False) );

{ 0 }

Writeln ( Ord(True) );

{ 1 }

,
, , .

, ,
. ,
.
if M2 > M1 then { }
if D1 = D2 then { }

226

32

if M2 > D1 then

{ }

if 'W' > 20 then

{ }

, .
if Ord(M2) = Ord(D1) then

{ }

if Ord(W) > 20 then

{ }

-
(INC) (DEC)
. , ,
? .
, : SUCC PRED.
SUCC ( SUCCESS , )
,
.
Writeln ( Succ(20) );

{ 21 }

Writeln ( Succ(D) );

{ E }

Writeln ( Succ(False) );

{ True }

m:= Succ(Feb);

{ m Mar }

PRED ( PREDECESSOR )
.
Writeln ( Pred(20) );

{ 19 }

Writeln ( Pred(D) );

{ C }

Writeln ( Pred(True) );

{ False }

m:= Pred(Feb);

{ m Jan }

SUCC PRED $R+.


, .
{ $R+ }
m:= Succ(Dec);

{ }

m:= Pred(Jan);

{ }

Borland Pascal : $R+ ,


SUCC PRED , .

227

32

{ $R+ }
var

B : byte;
. . .
B:=255;

B:= Succ(B);

{ }

B:=0;

B:= Pred(B);

{ }

Borland Pascal
$Q+, Overflow Checking
(. 73). $R+ $Q+ ,
.
{ $R+, Q+ }
var

B : byte;

{ 0 255 }

C : a..z;

{ }

C:=z;

C:= Succ(C);

{ R+ }

B:=255;

B:= Succ(B);

{ Q+ }


FORTO .
:
, .
var

m : (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec);
. . .
for m:= Jan to Dec do . . .

a z.
var

Sum : word;

Chr : char;

. . .
Sum:=0;
for Chr:= a to z

do Sum:= Sum + Ord(Chr);


:
CASEOF.

228

32

var

c : char;
. . .
Case c of
0..9: Writeln();
a..z: Writeln( );
A..Z: Writeln( );
end;

.
var

m : (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec);
. . .
Case m of
Jan, Feb, Dec

: Writeln();

Mar..May

: Writeln();

Jul..Aug

: Writeln();

Sep..Nov

: Writeln();

end;

, ,
.


$R+ $Q+, ,
.
, .
,
.

: , .
.
, ,
.
,
.
,
, .
$R+
, .
229

32

ORD .

SUCC PRED.
INC
DEC.
,
.

?
) , SizeOf ,
, .
Writeln( SizeOf( LongInt ) ); { 4 }
Writeln( SizeOf( M1

);

{ 1 }


.
)
(Byte, ShortInt ). , ,
:
var

N : -10..10;
M : -200..200;
R : 0..40000;
L : 0..400000;
S : 0..9;

) Writeln ,
. , ,
( CASE).

230

33

, , . !
, , ,

. -, . ,

LongInt. ? -,
.
. ?
. ,
.
. ? .


,
, . , .
: (
),
. , ,
.
3.33333343267441E-0002

,
E -0002. : ,
E, , .
,
, . ,
, ,
0.0333333343267441.
, ,
3.33333343267441E+0003


3333.33343267441.

, .
,
231

33

. ,
.
3.33333343267441E+2000
3.33333343267441E-2000

, (
).
.



, :
. ,
, .
, .
.
10/3, 3.3(3),
. .
{ }
begin
Writeln(F, 10/3);

{ }

Writeln(F, 10/3 : 12);

{ }

Writeln(F, 10/3 : 15:0);

{ }

Writeln(F, 10/3 : 15:2);

{ }

Writeln(F, 10/3 : 15:3);

{ }

end.

.
3.33333333333333E+0000
3.333E+0000
3
3.33
3.333

, . :
,
, .

232

33


.
.
. . . 3
.
. 3 Borland Pascal

()

Real

2.9 x 10-39

1.7 x 1038

11-12

Single

1.5 x 10-45

3.4 x 1038

7-8

Double

5.0 x 10-324

1.7 x 10308

15-16

Extended

3.6 x 10-4951 1.1 x 104932

19-20

10

,
? .
, .

.
{ }
var

F0 : Real;

F1 : single;

F2 : double;

F3 : extended;

begin
F0:= 1/3;

F1:= 1/3;

F2:= 1/3;

F3:= 1/3;

Writeln('Real

= ',

F0:23:18);

Writeln('Single

= ',

F1:23:18);

Writeln('Double

= ',

F2:23:18);

Writeln('Extended= ',

F3:23:18);

end.

1/3 ,
,
.

233

33

Real

0.333333333333484916

Single

0.333333343267440796

Double

0.333333333333333315

Extended=

0.333333333333333333

, Extended ,
. . ,
? .
,
.
Real. ,
.
, .
,
.
, Real.
, . 3. Extended
. ,
, , 10 .
?
, Extended . ,
. Single Double?
,
.


.
,
! , ,
, .
, . ?
, .
var

A, B : Extended;

. . .
if A = B

then

if Abs(A-B) < 0.001 then

{ }
{ 0.001}

A B ,
, . ,
. Abs ,
.
234

33


, ,
. , .
,
. ,
.
.
, ,
Integer. , ,
- , Longint Extended.
,
, . ,
.

, TYPE .
. ,
,
Integer.
Type

TValue = Integer;

TValue (Value ).
Integer. ,
, ,
.

. ,
.
C, a.
T ( Type). :
, .
, TValue ,
, .

235

33

Type

TValue = Integer;

Var

A, B, C : TValue;
. . .
Readln(A, B);
C:= A+B;

A, B C
Longint,
.
Type

TValue = Longint;

TValue
Longint.
.
, ,
. ,
.


!
! ,
, , .
. ,
: ?
.
, ,
. , .
,
. ,
.

,
. .
:
.
, , .

236

33

Var

B: Byte; I: Integer; W: Word; L: Longint;


. . .
{ }
I:= B;

W:=B;

L:= W;

L:=I;

{ }
B:=I;

I:=W;

W:=L;



; , . Ord
, . Char
, , .
Writeln ( Ord(D) );

{ 68 }

Writeln ( Char(68) );

{ D }

, Char?
, , ,
.

Ord.
Writeln ( Ord(False) );

{ 0 }

Writeln ( Ord(True) );

{ 1 }

Boolean.
Writeln ( Boolean(0) );

{ False }

Writeln ( Boolean(1) );

{ True }


,
, .
var

m : (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec);


Ord. ? .
.

237

33

Type

TMonth : (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec);

Var

m : TMonth;
. . .
m:= 3;

{ }

m:= TMonth(3);

{ , m:= Apr ( ) }

TMonth
(Month ), ,
. !

, .
,
, , ,
.

,
, .
.
, .
: ,
. ,
: Trunc , Round .
.
Writeln ( Trunc(3.75) );

{ 3 }

Writeln ( Round(3.75) );

{ 4 }

Writeln ( Round(3.25) );

{ 3 }

. 75
.

. ,
. ,
.
. : ,
, , , , .

238

33

Char ()
Char

Ord()
Boolean()

Byte,
ShortInt,

Boolean

Integer,
Word,
Longint,

()

Ord()

Ord()
Trunc (), Round ()

Real,

Single, Double, Extended

. 75


,
. , ,
. .

SizeOf.
, ,
. .

239

33

Type

TMonth : (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec);

Var

m : TMonth;
. . .
Writeln ( SizeOf(m) );

{ 1 }

Writeln ( SizeOf(TMonth) );

{ 1 }

Writeln ( SizeOf(Integer) );

{ 2 }

Writeln ( SizeOf(Extended) );

{ 10 }

SizeOf ,
, .
,
.
SizeOf ,
. , Object Pascal Delphi
Integer , .
SizeOf, Delphi
, .

,
.
,
.
,
.
, , .
.
,
.

,
Trunc, Round.

, .
TYPE,
.
, ,
SizeOf.
.
240

33

?
) :
(: 3.1 4; 3.9 4);
(: 3.1 3; 3.9 3).
, .
) String. ,
.
.

241

34

,
, 32- .


.
:

, ;

;

.
.
(. 76).

IF THEN

REPEAT UNTIL

IF THEN ELSE

WHILE DO

CASE OF END

FOR TO DO

. 76

242

34

,
:
IF...THEN... ;
IF...THEN...ELSE... ;
CASE...OF... ELSE...END.
:
REPEAT...UNTIL... ;
WHILE...DO... ;
FOR...TO...DO FOR...DOWNTO...DO.
,
!


(Section ,
).
. . 77 .

Const

Type

Var

Function
Procedure

Begin

end.

. 77
243

34

. Const,
Type Var .
, .
, ,
. , ,
. , , .
:
, ,
;
(
!).
.
-.
,
, .


,
. ,
.
, ,
( ).
,
.
.
.
.
, .
. 78,
ABC.

244

34

Procedure ABC ()

Const

( )

Type
Var

Begin
. . .
end;

. 78

, , ,
.
( ) ,
, :
;
.
,
.
, ,
.




. , ,
. .
, :
;
;
.
245

34

,
.
.

. .
,
. . 4
.
. 4

:


.

Procedure ABC (arg:integer);

ABC(10);
ABC(X+3);

CONST:



,
.

Procedure ABC (const


arg:integer);

ABC(10);
ABC(X);

VAR:


,
.

Procedure ABC (var


arg:integer);

ABC(X)

; . 5
.
. 5


1) ( )


2) CONST ( )
1)

2) VAR

VAR

246

34

.
. CONST
.
, ,
VAR.


, ,
, .
.
.
.
, .

?
,
. ,
. ,
. ? ,
, !

:
, .
.
: 1)
, 2) 3) .
. ,
.
, .
,
.
.
, .

.
, .

.

247

34

?
) .
var X : TNum;
type TNum = integer;
const A = 10;
begin
X:= A+B;
end.

248

35

, -
! ?
...
. !


. ,
,
. - ( ),
.
,
. ? .
,
- . ,
, .
, ,
. , ,
, .
: ! !

,
,
. ,
, , .
, . ,

. ,
. .
2 11 4 13
9 17 12 11 3 5 18
14 2 13 15 20

4 , 7, 5
. , ,
.
( 1 250), .
,
.

249

35


-. ?
! , , .
, ! ,
, ,
. .

B (Black)


W (White)

. 79 (B) (W)

, ? , ,
, .
B ( Black ), W ( White ). ,
.
? , ,
. ?

,
, . ,
, . ,
,
. :
B+B=B
:
W+W+W=W
, ?

250

35


.
, .

G (Gray)
+W
G =GB=+BW

. 80 G = B + W

,
. G ( Gray )
, , .
G=B+W
,
. ,
B W, , . ,
(. 81).


G<B+W

. 81 G < B + W

,
.
G<B+W
( ,
) .
GB+W

251

35


( )
, (. 82).

G=B*W

W
G

. 82 G = B * W

.
G=BW
, , ,
B W. :
.
BWB BWW

, .
, . 83
?
. ,
, .
.
G=BW

G=WB

252

35


G=BW


G=WB

. 83

, ,
? , ?
!
, .
, .
(B B) B =
( W) B =
!


.
.
. :

1 9 (. 84).
( , ).

253

35

5
7
9

1
. 84

. ,
A, 8, 7, 9, 3, 5, 2. B
5, 4, 6, 1, 2. .
A = { 8, 7, 9, 3, 5, 2 }
B = { 5, 4, 6, 1, 2 }
. :
. ,
. , 2 5
.
, ,
, .
,
.
. , .
A + { 8, 7 } = A
A {8,7} ,
.
, :
, .
.
,
() :
254

35

1}

G = A + B = { 8, 7, 9, 3, 5, 2 } + { 5, 4, 6, 1, 2 } = { 8, 7, 9, 3, 5, 2, 4, 6,

2 5 ,
.
,
:
A * B = { 8, 7, 9, 3, 5, 2 } * { 5, 4, 6, 1, 2 } = { 5, 2 }
AB , A,
B:
A B = { 8, 7, 9, 3, 5, 2 } { 5, 4, 6, 1, 2 } = { 8, 7, 9, 3 }
BA , B,
A:
B A = { 5, 4, 6, 1, 2 } { 8, 7, 9, 3, 5, 2 } = { 4, 6, 1 }
. 84.

,
,
. .
, , .
A+B.
, , .
, A B .
. ,
? , ,
.

(, ),
.
.
: , ,
.

255

35


.
.
, .

.

?
)
, .
: , , .
: , , , , .
?
?

?
- ,
.
?
: .
, ?
) , A B, ,
. ,
, :
?
, .
, G = (A-B) + (B-A).
, G = A+B
, ?

256

A*B.

36

,
.
,
, . ,
256.



SET

OF

< >

var

{ }

{ }

SN1 : set of 10..100;

{ 10 100 }

SN2 : set of byte;

{ 0 255 }

SC1 : set of a..z;

{ }

SC2 : set of Char;

{ }

256,
SET OF BYTE SET OF CHAR .



, .
SN1:= [10, 20, 50];

{ }

SN2:= [11..20, 51..60];

{ 20 }

SN2:= [0..255];

{ 256 0 255 }

SN2:= SN1;

{ }

SC1:= [z, y, x];

{ }

SC2:= [0..9];

{ 10 }

, ,
.
, ?
.
,
257

36

.
.
SN1:= [5..8];

{ }

SN1:= [8, 7, 6, 5];

{ , }

SN1:= [5..8, 6, 6];

{ 6, }

, .
SB1:= [];

SN1:= [];

SC1:= [];

,
. [0],
.

.
var

k, n : byte;

c: char;

. . .
k:= 10;

n:= 20;

SN1:= [1..k, n+5];

{ 1..10, 25 }

c:= m;
SC1:= [c, a, b);

{ m, a, b }

, ,
, .
SN1:= [5..200];

{ SN1 10 100 }

SC1:= [a, b, 5];

{ 5 5 }



,
.
,
.

258

36

SN2:= [3, 7] + [5, 2];

{ = [2, 3, 5, 7] }

SN2:= [2..10] * [8..20];

{ = [8, 9, 10] }

SN2:= [2..10] [8..20];

{ = [2..7] }

, ,
, .
SN2:= (SN1 + [0..15]) * SN2;

, ,
, .
.
, ,
K. .
SN1:= SN1 + K;

{ }

.
SN1:= SN1 + [ K ];

{ }

, ,
.


,
TRUE FALSE.
, .
if SN1 = SN2

then

else

, , ,
.
if SN1 <> [15, 17, 19] then

else

(<=) :
?
if SN1 <= SN2

then

else

(=>) ,
.
259

36

if SN1 => SN2

then

else

( IN)
? .
var N : byte;

S : set of byte;

. . .
if ([N] * S) <> [] then { N S } else { }

, N S, [N]*S
. IN .
TRUE,
, .
if N in S

then { N S } else { }

if 20 in S

then { 20 S } else { }


.
: ,
, .
2 11 4 13
9 17 12 11 3 5 18
14 2 13 15 20

.
? , ,
:
(
);
;
( ).
, ?
. ,
. , .
, ,
- (S1 + S2 + S3).
260

36

, .
! .
var

R, S1, S2, S3 : set of 1..250;

begin
S1:= [ 2, 11, 4, 13 ];

{ 1- }

S2:= [ 9, 17, 12, 11, 3,, 5, 18 ]; { 2- }


S3:= [ 14, 2, 13, 15, 20 ];

{ 3- }

R:= [1..250] (S1 + S2 + S3);

{ R }

end.

,
. , ! ,
!
,
. .
?
, R .
.

, .
,
, .
256.
: ,
, ,
.
,
.

IN
, .

261

36

?
) .
type TNumbers = set of 1..300;
TChars = set of char;
TBytes = set of byte;
var c1, c2 : TChars;
b1, b2 : TBytes;
begin
c1:= [1..9];
c2:= ['1'..'9'];
c2:= c2 + 0;
c2:= c2 + [0];
b1:= c1;
b2:= b1 + [1,7,3];
Writeln(b1=b2);
Writeln(1 in b2);
Writeln([1] in b2);
Writeln(b1 in b2);
end.

262

37


.
. -
Read(ln) Write(ln). ,

. ,


( ,
). .
. Writeln
,
. ,
, . , IN,
. ,
.
.
{ P_37_1 }
type

TSet = set of 1..255;

{ }

{----- -----}
procedure WriteSet(var aFile: text; const aSet : TSet);
var k : integer;
begin
for k:=1 to 255 do
if k in aSet

{ }
{ K }

then Write(aFile, k:4); { }


Writeln(aFile);

{ }

end;

263

37

{----- WriteSet -----}
var

S1 : TSet;

F: text;

begin
Assign(F, ''); Rewrite(F);

{ ! }

S1:= [3, 10, 25];

{ }

WriteSet(F, S1);

Readln;

{ }

Close(F);
end.

TSet,
1 255. WriteSet :
, .
FOR,
. , , .
Writeln
.
Assign(F,''),
.
( ), (
). , ,
, WriteSet.
. Pascal ABCNet.

.
, .
?
, .
, ,
. ,
.

264

37

{ P_37_2 }
type

TSet = set of 1..255;

{ }

{----- -----}
procedure ReadSet(var aFile: text; var aSet : TSet);
var

k : integer;

begin
While not Eoln(aFile) do begin

{ }

Read(aFile, K);

{ }

aSet:= aSet+[K];

{ }

end;
Readln (aFile);

{ }

end;
{----- -----}
procedure WriteSet(var aFile: text; const aSet : TSet);
var k : integer;
begin
for k:=1 to 255 do

{ }

if k in aSet

{ }

then Write(aFile, k:4); { }


Writeln(aFile);

{ }

end;
{----- -----}
var

S1 : TSet;

F, D: text;

begin
Assign(F, ''); Rewrite(F);

{ }

Assign(D, ''); Reset(D);

{ }

S1:= [];

{ }

ReadSet(D, S1);

{ }

WriteSet(F, S1);
Close(F);

Readln;

{ }

Close(D);

end.

, .
. , :
, ,
Enter.

,
,
. ,
.
265

37

R:= [1..250] (S1 + S2 + S3);

. ,
, .
{ P_37_3 , 1 }
const CMax = 20;
type

{ , 250 }

TSet = set of 1..CMax; { }

procedure WriteSet(var aFile: text; const aSet : TSet);


{ P_37_2 }
procedure ReadSet(var aFile: text; var aSet : TSet);
{ P_37_2 }
var

R, S1, S2, S3 : TSet;


FileIn, FileOut: text;

begin {----- -----}


{ }
Assign(FileIn, 'P_37_3.in'); Reset(FileIn);
{ }
Assign(FileOut, 'P_37_3.out'); Rewrite(FileOut);
{ }
S1:=[];

ReadSet(FileIn, S1);

S2:=[];

ReadSet(FileIn, S2);

S3:=[];

ReadSet(FileIn, S3);

R:= [1..CMax] (S1+S2+S3);

{ }

WriteSet(FileOut, R);

{ }

Close(FileIn);

Close(FileOut);

end.

,
Readln . ,
CMax 250 20.
.

266

37

2 11 4 13
9 17 12 11 3 5 18
14 2 13 15 20

.
1

10

16

19

, .

,
, , .
.
, .
-, .
; .
20
2 11 4 13
9 17 12 11 3 5 18
14 2 13 15 20

-, ,
. , ,
, .
. ,
( ).
{ P_37_4 , 2 }
type

TSet = set of byte;

{ }

{ }
procedure WriteSet(var aFile: text; const aSet : TSet);
{ P_37_2 }
procedure ReadSet(var aFile: text; var aSet : TSet);
{ P_37_2 }

267

37

var

R, S : TSet;
FileIn, FileOut: text;
N: integer; { }

begin
Assign(FileIn, ' P_37_4.in'); Reset(FileIn);
Assign(FileOut, ' P_37_4,out'); Rewrite(FileOut);
Readln(FileIn, N);
S:= [];

{ }

{ }

{ , }
while not Eof (FileIn) do ReadSet(FileIn, S);
R:= [1..N] S;

{ }

WriteSet(FileOut, R);
Close(FileIn); Close(FileOut);
end.

, , .
.


, .
() ,
.

.

?
) .
?
) ,
.
)
, . ?

268

38

, ... !
, ? ,
!

, ?
, .
, , .
, .
?
, ,
S1, S2 S3. ,
S1 S2 , S1*S2.
: S1 S3, S2 S3. ,
. , .
R := S1*S2 + S1*S3 + S2*S3;

R , ? ,
, ? , , :
:
;
.
, . , ,
P_38_1, , !



.
. , ,
. : A,
B, C ,
. ,
, , .
. 6.

269

38

. 6

1 2 4 5 9 11 13 15 22 23 24 25 27 30 31 37 41 42 43 44 45
46 48 50 51 56 64 70 72 73 74 75 76 77 82 84 86 87 89 92 95
97 98 101 102 103 104 105 106 107 108 111 113 116 117 118 124 125 127
130 132 133 134 138 143 144 145 147 149 150

16 21 22 23 24 25 26 27 28 29 31 33 35 37 39 41 44 47 49 50
51 52 54 55 56 57 59 61 62 65 66 69 70 71 72 77 78 79 81 83
84 85 91 92 93 94 95 96 98 100 101 103 107 108 109 112 113 115 117
118 119 121 122 124 129

1 3 5 9 12 19 22 25 33 34 41 42 46 50 52 55 56 57 58 59 61
66 69 72 80 81 82 84 87 88 94 97 99 100 101 102 112 119 121 123
125 129 134 137 138 139 149 152 153 154 155 157 158 165 166 168 171
172 180 184 185 190 193 194 198 199 205 213 216 220

5 6 7 8 9 10 11 12 13 14 16 18 21
32 34 35 38 40 41 42 43 44 45 46 47
59 60 61 62 63 64 65 66 67 70 71 73
84 85 86 88 89 91 92 93 94 95 96 97
108 111 112 113 115 116 117 118 119 120

10 15 16 26 33 40 42 44 50 53 65 67 74 79 82 83 85 87 90 91
93 99 106 108 110 120 121 124 125 132 135 146 148 149 151 156 157 158
163 166 168 169 171 175 183 184 189 195 197 205 206 207 216 220 221
225 226 227 241 244

8 12 21 25 26 29 30 31 34 48 49 50 52 55 59 60 62 70 71 73 83
85 90 91 92 93 94 96 97 99 100 102 103 104 105 106 108 119 121 122
124 127 128 130 132 141 142 144 156 160 165 166 169 171 173 176 179
191 192 195 199 200 207 209 220 221 222 224 226 229 233 234 236 239
240

23 24 26 27 29 30 35 36 41 42 44 45 46 49 52 55 56 58 60 61
63 64 65 68 72 74 76 77 81 82 86 87 88 90 93 94 95 96 97 98
100 101 102 107 108 109 112 113 114 115 117 120 123 127 132 133 135
137 138 143 145 146 147 150 152 155 156 159 161 162 163 164 165 168
170 172 177 178 179 180

15 17 19 20 21 22 23 26 28 29 30 32 33 34 36 38 41 42 44 45
46 48 49 52 57 60 62 65 66 68 73 74 77 78 83 84 85 88 89 90
91 92 95 96 97 98 99 100 101 102 103 104 107 108 115 116 118 127
128 129 130 131 134 135 136 137 139 145 146 150 151 152 154 157 160
161 164 166 167 172 173 177 178 179 180 182 185 188 189 190 193 195
197 204 207

22
48
74
98

23 24 27 28 29 30 31
51 52 53 54 55 57 58
75 76 78 79 80 81 82
99 100 104 105 106 107

,
A, D, G H ( ).
270

38

(B, C, E F)
. .
, , ,
. ,
,
. , , 30
, 45.
, .
? ,
, .
{ P_38_2 }


,
-. ,
: A, B, C
. . ,
; .
,
.
A. ,
,
. ,
. ,
,
.
, .
, . . 85
, . ,
.
A. , ,
. , A ,
. .
.
,
.
.

271

38

1
17

H
16

14

3
18

28

15

29

32

27

13

19

20
31

A
21

26

30

12

22

23
24

11
25
10

. 85

,
, , , .
, , . ,
. ! , ,
, !.
. ,
. , ! .
? , ,
. , , !. ,
, ,
. ,
.

272

38

29 21 30 31 32
17 18 19 29 28
3 4 5 20 19 18
6 7 22 21
8 9 25 24 23 22
10 11 26 30 23 24 25
12 13 15 27 26
14 1 2 17 16 15
16 28 32 31 27

, ,
: A, B
. ,
. , A
.
, .
, !
,
. ,
: , , ,
( , ?).
, ,
( , ).
, . .
{ P_38_3
type

TBoundSet = set of byte;

{ }

TStateSet = set of Char;

{ }

{ () }
procedure WriteCharSet(var aFile: text; const aSet : TStateSet);
var c : char;
begin
for c:='A' to 'Z' do

if c in aSet then Write(aFile, c:2);

Writeln(aFile);
end;

273

38

{ () }
procedure ReadSet(var aFile: text; var aSet : TBoundSet);
var k : integer;
begin
While not Eoln(aFile) do begin
Read(aFile, K);

aSet:= aSet+[K];

end;
Readln (aFile);
end;
var

FileIn, FileOut: text;


R: TStateSet;

{ () }

SA, S : TBoundSet;

{ A }

State: char;

{ }

begin

{ }
Assign(FileIn, 'P_38_3.in'); Reset(FileIn);
Assign(FileOut, ''); Rewrite(FileOut);
R:= [];

SA:=[];

State:='A'; { A }

ReadSet(FileIn, SA);

{ A}

while not Eof (FileIn) do begin

{ }

State:= Succ(State);

{ }

S:=[]; ReadSet(FileIn, S);

{ }

{ A, }
if S*SA <> [] then R:= R + [State];
end;
WriteCharSet(FileOut, R);
Close(FileIn);

Readln; { }

Close(FileOut);

end.

, A B,
D, F, I. .
, .
.
, .
, .
? .


,
, .
274

38

, ,
, !
.
, , . ,
.
. , , 1 10
.
1 2 3 4 5 6 7 8 9 10

4, 6, 8, 9 10,
2, 3. 1, 2, 3, 5 7 .
- :
, ? , , 1, 2, 3
5 , (7). ,
!
, !
. ,
,
N. .
, N, N
20. 1 20.
1 2 , , , 4,
6, 8 .
.
: 6, 9, 12, 15 18 ( ,
). , .
: 10, 15, 20 ( ).
11, .
, .
,
, .
.

275

38

1- , 2:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
2- , 3:
1 2 3 * 5 * 7 * 9

* 11

* 13

* 15

* 17

* 19

* 17

* 19

:
1 2 3 * 5 * 7 * *

* 11

* 13

? ?
, , ? P_38_4
, 255.
.
program P_38_4;

{ }

var Simples : set of byte;

{ }

n, m : integer;
F : text;
begin
Assign(F, 'P_38_4.out'); Rewrite(F);
Simples:= [2..255];

{ }

{ }
for n:=2 to (255 div 2) do begin
{ }
if n in Simples then
{ }
for m:=2*n to 255 do
{ (m/n) , m }
if (m mod n)=0
{ }
then Simples:= Simples [m];
end;
{ }
for n:=2 to 255 do if n in Simples then Writeln(F,n);
Close(F);

Readln;

end.

,
,
. S
.

276

38

Writeln (, + S);

, .
, .
(, , ), .
C .
C:= S[Length(S)];

.
if (C=) or (C=) or (C=) or (C=)
then Writeln (, + S)
else Writeln (, + S);

C
, , .
, ,
.
if C in [, , , ]
then Writeln (, + S)
else Writeln (, + S);

C . ,
.

, , ,
, .

?
)
. ?
)
, , .
-,
256. 0 255,
.
, 7, . ,
5, , .
277

38

, , 35 70 , ,
5.
, .
4, , 3 ,
2 , .
,
. (: 37, 44,
175).
, ,
. (: 64,
64, 43, 85).
.
. ,
,
. .
?

278

39
()
?
, , !
, .
. , , . ,
, .


:
.
, 16. ,
. ? !
, ,
, .
.
,
. ?
{ ( 14 ) }
var T1, T2 : integer;
begin
Readln (T1, T2);

{ }

if T1>T2
then

begin
Writeln('1.');
Writeln('2.');
end

else

begin
Writeln('1.');
Writeln('2.');
end

Readln;
end.

, :
T1 , T2 .
, , 14 , .
.
, , .
279

39
()
{ ( 45 ) }
var T1, T2, T3 : integer;
begin
Readln (T1, T2, T3);

{ , , }

if (T1>T2) and (T1>T3)


then begin
Writeln('1.');
if T2>T3
then begin
Writeln('2.');
Writeln('3.');
end
else begin
Writeln('2.');
Writeln('3.');
end
end
else begin
if (T2>T1) and (T2>T3)
then begin
Writeln('1.');
if T1>T3
then begin
Writeln('2.');
Writeln('3.');
end
else begin
Writeln('2.');
Writeln('3.');
end
end
else begin
Writeln('1.');
if T1>T2
then begin
Writeln('2.');
Writeln('3.');
end
else begin
Writeln('2.');
Writeln('3.');

280

39
()
end
end
end;
Readln;
end.

45 , .
.
4 (180
), 5 (900 ) .
, !
! , ,
!

?
?
, .
, . !
T1, T2 T3, .
.
, .
,
? !
, . ,
!



. ,
. .
. ,
, , .
.
,
(. 86).

281

39
()

. 86 () ()

, .
.
. , ?


, , .
VAR, TYPE.
, VAR.
VAR

_ : ARRAY [MIN..MAX] OF _

ARRAY OF,
.
: .
, .
,
. , .

. ARRAY
,
282

39
()

MIN MAX. .
, .
OF,
. ,
, .
: Names (), Ratings
() ChampShip ().
VAR

{ - }
{ 30 }
Names : ARRAY [1..30] OF string;
{ 30 }
Ratings : ARRAY [1..30] OF byte;
{ 16 , }
ChampShip : ARRAY [1..16] OF integer;

, . ,
Names 30 : Names[1],
Names[2] ( ).
VAR . ?
.
var

A : array [1..5] of integer;


B : array [1..5] of integer;

begin
A:= B; { }
end.

: A B. ,
, .
, , .
,
A:=B

B A. ,
. ? ,
, .
283

39
()

! , ,
- , .
-, A B .
var

A, B : array [1..5] of integer;

.
,
. TYPE .
TYPE

_ = ARRAY [MIN..MAX] OF _

:
, . !
,
. , .
TYPE

{ - }
{ 30 }
TNames = ARRAY [1..30] OF string;
{ 30 }
TRatings = ARRAY [1..30] OF byte;
{ 16 , }
TChampionShip = ARRAY [1..16] OF integer;

T
( ?).
,
.
VAR

{ 30 }
Names : TNames;
{ 30 }
Ratings : TRatings;
{ 16 , }
ChampionShip : TChampionShip;

284

39
()
procedure ABC (var arg: TRatings); { }
var

A, B, C : TRatings;

{ }

begin
. . .
end;

TRatings
. ,
, , .

()
- , ,
.
, ?
, ,
. ,
, .
, ,
.
, ,
.
.
1.
.

Names

Names[1]:= ;
Names[2]:= ;
Names[3]:= ;

2. Ratings.
.
i:=3;
if Ratings[i] > Ratings [i+1] then else ;

, ,
! .

285

39
()


, ,
. , ,
. , , ,
.
, , Names, .
for i:=1 to 30 do Readln(F, Names[i]);

, F ,
.
. , .
, 30 ( ).
, . ?
, .
i:=1;
{ }
while not Eof(F) and (i<=30) do begin
Readln(F, Names[i]);
i:= i+1;
end;

.
for i:=1 to 30 do begin
if Eof(F) then break;

{ , }

Readln(F, Names[i]);
end;

, .
for i:=1 to 30 do Writeln(F, Names[i]);

, F .


, , : MIN
, MAX .
, MIN ? , , ,
MAX? ,
286

39
()

?
. ,
.
, .
Names[200]:= ;

Names 200.
, , .
, , .
, ,
, .
Readln(N);
Writeln(Names[N]);

, N,
.
27 ,
. , ,
,
. , $R,
:
Options Compiler Runtime Errors Range checking
($R+).
, ,
Range check error. , ,
.
($R-) .
,
. , . ,
!
.
,
. .

287

39
()
repeat
Readln(N);
if N in [1..30]
then Writeln(Names[N])
else Writeln(! 1 30);
until N in [1..30]

,
( ).

,
, .
, .

.
:
.

.
,
.
( )
, .

?
) A .
var

A : array [a..z] of integer;


C: char;

?
? ( )
?
A[s]:= 10;
A[R]:= 10;
C:=d;

A[C]:= 10;

Readln(C);

A[C]:= 10;

.
288

40

, .
,
, . , -
.

-
16- ,
. ,
. ,
.
.
.
, , .
? , , .
? , ?
,
, . ,
100 .
.
. ,
,
.
, P_40_1.
{ P_40_1 "-" }
const CAnswers = 100;

{ }

{ }
type

TAnswers = array[1..CAnswers] of string;

var

Answers : TAnswers;

{ }

Fact : integer;

{ }

F : text;

{ }

S : string;

{ }

289

40

{ }
procedure ReadFromFile(var aFile: text);
var i: integer;
begin
Fact:=0;

{ }

{ }
for i:=1 to CAnswers do begin
if Eof(aFile) then Break;

{ }

Readln(aFile, Answers[i]);

{ }

Fact:= Fact+1;

{ }

end;
end;
begin

{--- ---}
Assign(F, 'P_40_1.in');

Reset(F);

ReadFromFile(F);
Close(F);
Randomize;

{ }

{ }
repeat
Write(' : ');
if S<>'' then

Readln(S);

Writeln(Answers[Random(Fact)+1]);

until S='';
end.

P_40_1.IN
ReadFromFile ( ), Answers
(). Fact.
, ,
100 , , , Fact.
, :
.

Random(Fact)+1. , Random(Fact)
0 Fact-1, .



( 29).
. , ,
! ? ,
, ,
, !
290

40

P_40_2
. Read,
ReadFromFile.
. ,
.
{ P_40_2 }
const CNumbers = 1000; { }
{ }
type

TNumbers = array[1..CNumbers] of integer;

var

Numbers : TNumbers;

{ }

Fact : integer;

{ }

F : text;

{ }

Num : integer;

{ }

{ }
procedure ReadFromFile(var aFile: text);
var i: integer;
begin
Fact:=0;

{ }

for i:=1 to CNumbers do begin

{ }

if Eof(aFile) then Break;

{ }

Read(aFile, Numbers[i]);

{ }

Fact:= Fact+1;

{ }

end;
end;
{ }
function FindNumber(aNum: integer): boolean;
var i: integer;
begin
FindNumber:= false;
for i:=1 to Fact do
if aNum=Numbers[i] then begin
FindNumber:= true;

{ ! }

Break;

{ }

end
end;

291

40

begin

{--- ---}
{ }
Assign(F, 'P_38_2.in');
ReadFromFile(F);

Reset(F);
{ }

Close(F);
repeat

{ }

Write(' : ');

Readln(Num);

if FindNumber(Num)
then Writeln(' , !')
else Writeln(' ');
until Num=0;

{ 0 }

end.


, . ,
. ,
, .
- , .
, .
a

119

45

72

( )

,
. ,
a z.
,
. 26 , .
, .
type TCounts = array [1..26] of integer;

. ,
. , ,
. , .

292

40

type

TA = array ['A'..'F'] of integer;


TB = array [false..true] of integer;

6 , .
, .
,
.
type TCounts = array ['a'..'z'] of integer;

, ,
,
.
.
, .
{ P_40_3 }
{ , }
type TCounts = array ['a'..'z'] of integer;
var

Counts : TCounts; { }
c: char;

{ , }

F : text;

{ }

begin

{--- ---}

{ }
for c:='a' to 'z' do Counts[c]:=0;
{ }
Assign(F, 'P_40_3.pas');

Reset(F);

while not Eof(F) do begin { }


Read(F, c);

{ }

if c in ['a'..'z']

{ }

then Counts[c]:= Counts[c]+1; { }


end;
Close(F);
{ }
for c:='a' to 'z' do Writeln (c, Counts[c]:6);
Write(' Enter'); Readln;
end.


. , ?
293

40

, , .
,
.
.
.

?
)
( , !).

294

41
!
39- , ,
.
, , .


, .
.
, ,
. , :
, .
, .
.
, , .
, ? .
, .
, . ? .
(
), ,
.
, , .
.
, .

(. 87).
, , ? ,
.
,
,
.
, , ,
.
.
.
. ,
295

41
!

. , ,
. ,
. ,
.
N-1 , N , :
, .
1

(3 4)

(2 5)

(1 6)

. 87

, , ,
. .


. :
, .
Bubble Sort.
? .
.
- 10
.
P_41_1,
. .
BubbleSort,
.
.
FORTO, . J
296

41
!

, , . T
.
. ,
CSize , CSize-1 ,
I.
{ P_41_1 }
const CSize = 10; { }
{ }
type
var

TGolds = array [1..CSize] of integer;


Golds : TGolds;

{ }

{ "" }
{ ! - ! }
procedure BubbleSort (var arg: TGolds);
var

i, j, t: Integer;

begin
for i:= 1 to CSize-1 do

{ }

for j:= 1 to CSize-1 do

{ }

{ ...}
if arg[j] > arg[j+1] then begin
{ }
t:= arg[j];

{ }

arg[j]:= arg[j+1];

{ -> }

arg[j+1]:= t;

{ -> }

end;
end;

297

41
!
var i:integer; { }
begin {--- ---}
{ }
Randomize;
for i:=1 to CSize do Golds [i]:= 1+Random(1000);
{ }
Writeln(' :');
for i:=1 to CSize do Writeln(Golds [i]:3);
{ }
BubbleSort(Golds);
{ }
Writeln(' :');
for i:=1 to CSize do Writeln(Golds [i]:3);
Readln;
end.


, .
. ,
.
,
. .
, .
for j:= 1 to CSize i do

{ }


( I ).
.


,
.
. , .
, .
, ,
. , I-
I CSize+1-I. P_41_2 ,
.

298

41
!
{ P_41_2 }
const CSize = 16; { }
{ }
type
var

TGolds = array [1..CSize] of integer;


Golds : TGolds;

{ }

{ "" }
procedure BubbleSort (var arg: TGolds);
var

i, j, t: Integer;

begin
for i:= 1 to CSize-1 do

{ }

for j:= 1 to CSize-i do

{ }

{ ...}
if arg[j] > arg[j+1] then begin
{ }
t:= arg[j];

{ }

arg[j]:= arg[j+1];

{ -> }

arg[j+1]:= t;

{ -> }

end;
end;
var i:integer; { }
begin
{ }
Randomize;
for i:=1 to CSize do Golds[i]:= 500 + Random(500);
{ }
BubbleSort(Golds);
Writeln(' :');
for i:=1 to (CSize div 2) do begin
{ }
Write(i:2, Golds[i]:5,' + ',Golds[CSize+1-i]:3,' = ');
{ }
Writeln(Golds[i]+Golds[CSize+1-i] :4);
end;
Readln;
end.

299

41
!
:
1

506 + 975 = 1481

556 + 967 = 1523

587 + 954 = 1541

629 + 916 = 1545

691 + 876 = 1567

694 + 872 = 1566

749 + 845 = 1594

751 + 800 = 1551

: 506
975 . , , .


,
( 39, ?). ?
? , - .
. : () ,
() .
,
. , ,

. , .
.
, .
,
, . ?
: .
, P_41_3.

300

41
!
{P_41_3 }
const CSize = 16; { }
{ }
type
var

TAces = array [1..CSize] of integer;

{ }

TNames = array [1..CSize] of string;

{ }

Aces : TAces;

{ }

Names: TNames; { }
{ "" }
procedure BubbleSort2(var arg1: TAces; var arg2: TNames);
var

i, j, t: Integer;
s: string;

begin
for i:= 1 to CSize-1 do

{ }

for j:= 1 to CSize-i do

{ }

{ ...}
if arg1[j] < arg1[j+1] then begin
{ }
t:= arg1[j];

{ }

arg1[j]:= arg1[j+1];

{ -> }

arg1[j+1]:= t;

{ -> }

{ }
s:= arg2[j];

{ }

arg2[j]:= arg2[j+1];

{ -> }

arg2[j+1]:= s;

{ -> }

end;
end;
var i: integer;
begin

{ }

{ }
for i:=1 to CSize do begin
Write(' : '); Readln(Names[i]);
Write(' :

'); Readln(Aces[i]);

end;
BubbleSort2(Aces, Names);

{ }

Writeln(' :');
Writeln('

');

for i:=1 to CSize do


Writeln(i:3,' ':3, Names[i], Aces[i]:20-Length(Names[i]));
Readln;
end.

301

41
!

,
.
20 Length(Names[i])

,
, .

, ( CSize
4), .
:

55

54

47

43

, .


.
.
,
.

?
)
. ,
( ).
)
.
) (
). ( ,
)?

302

42
,
-: - ,
, . : ,
. ! ,
.

, ?
40- .
. !
! - , . , ?
? ? ,
, .
,
: , , .
const CNumbers = 100;
type

{ }

TNumbers = array[1..CNumbers] of integer;


TNames = array[1..CNumbers] of string;

var

Numbers : TNumbers;

{ }

Names : TNames;

{ }

Names (), ,
.
Numbers. , Numbers[7] 123,
Names[7] .., . 11-22-33,
123.
Names Numbers? .
,
.


40-
.
function FindNumber(aNum: integer): boolean;

FindNumber ,
Numbers, . ,
, .
303

42
,

? ,
, .
,
FindSeq ( Find , Sequence ).
{ Numbers aNum }
function FindSeq (aNum: integer): integer;
var i: integer;
begin
FindSeq:= -1;

{ , -1 }

for i:=1 to Fact do


if aNum=Numbers[i] then begin
FindSeq:= i;

{ , }

Break;

{ }

end
end;

,
,
.
, .
.
, .
, !
,
? ?
. , , .
, ,
. ,
. ,
. ,
, .



. , ,
, ,
. , .
, .
. 88.

304

42
,

4
3

5
6

. 88

, ( )
. ,
.
?
? , , ! ,
. . 89 ,
12 . .
32, ()
.
, 8 , 32 8-
. .
, .
, :
(1+12)/2 = 6

305

42
,

10

12

18

15

21

27

32

40

44

49

52

3
1

10

11

(1+12) / 2 = 6

27

32

40

44

49

12

52

10

11

(7+12) / 2 = 9

27

32

(7+8) / 2 = 7

32

8
. 89

306

12

42
,

,
. , 6 21, 32.
, - . , ,
, , .
, ,

(7+12)/2 = 9
40 32.
, , , ,
, . , 12
. ,
(7+8)/2 = 7
27. , ,
32.
: 8 ,
4 . : -?
. ,
. ,
, .


.
, -
(. 90). -, ,
: L
(Left), R (Right) M (Middle).

307

42
,

:= -1
L:=1
R:=

Repeat


M:= (L+R) / 2

:=M


R:= M -1


L:= M+1

L<=R
UNTIL L > R

. 90 -

, , FindBin (Find
, Binary ), . ,
.

308

42
,
{ }
function FindBin (aNum: integer): integer;
var L, M, R : integer; { , }
begin
FindBin:= -1;

{ }

L:= 1;

{ }

R:= CSize;

repeat
M:= (L+R) div 2;

{ }

if aNum= ArrSort[M] then begin


FindBin:= M;

{ ! }

Break;

{ }

end;
if aNum > ArrSort[M]

{ ? }

then L:= M+1

{ }

else R:= M-1;

{ }

until L > R;

{ }

end;

.
?
. 1000 .
. ,
. ,
:
, .
, .
, .

: , ,
.
Steps ().
, (
). ,
, .

309

42
,
{ P_42_1

- }

const CSize = 1000; { }


{ }
Type

TNumbers = array [1..CSize] of integer;

Var

ArrRand : TNumbers;

{ }

ArrSort : TNumbers;

{ }

Steps

{ }

: integer;

{ "" }
procedure BubbleSort(var arg: TNumbers);
var

i, j, t: Integer;

begin
for i:= 1 to CSize-1 do

{ }

for j:= 1 to CSize-i do { }


if arg[j] > arg[j+1] then begin

{ }

t:= arg[j]; arg[j]:= arg[j+1]; arg[j+1]:= t;


end;
end;
{ (Find Sequence) }
function FindSeq (aNum: integer): integer;
var i: integer;
begin
FindSeq:= -1;

{ , -1 }

for i:=1 to CSize do begin


Steps:= Steps+1;

{ }

if aNum= ArrRand[i] then begin


FindSeq:= i;

{ , }

Break;

{ }

end;
end;
end;
{ (Find Binary) }
function FindBin (aNum: integer): integer;
var L, M, R : integer;
begin
FindBin:= -1;
L:= 1;

R:= CSize;

repeat
Steps:= Steps+1;

{ }

M:= (L+R) div 2;


if aNum= ArrSort[M] then begin
FindBin:= M;

{ ! }

310

42
,
Break;

{ }

end;
if aNum > ArrSort[M]
then L:= M+1
else R:= M-1;
until L > R;
end;
{--- ---}
Var

i, n, p : integer;

{ }

F: text;

{ }

begin
Assign(F,'P_40_1.OUT');

Rewrite(F);

{ }
for i:=1 to CSize do ArrRand[i]:=1+Random(10000);
ArrSort:= ArrRand;

{ }

BubbleSort(ArrSort);

{ }

repeat

{ }

i:= 1+ Random(CSize);

{ }

n:= ArrRand[i];

{ }

Writeln(F,' = ', n);


Steps:=0;

{ }

p:= FindSeq(n);

{ }

Writeln(F,': ', '= ',


p:3, '

= ', Steps);

Steps:=0;

{ }

p:= FindBin(n);

{ }

Writeln(F,' :
p:3, '

', '= ',

= ', Steps);

Write(' 0 '); Readln(n);


until n=0;
end.

311

42
,
= 5026
: = 544

= 544

= 10

= 518

= 8528
: = 828

= 828

= 10

= 854

= 7397
: = 100

= 100

= 9

= 748

20 , . 7.

.
. 7-

1
5026
2
8528
3
7397
4
2061
5
8227
6
9043
7
4257
8
3397
9
4021
10
8715
11
6811
12
5959
13
928
14
3295
15
9534
16
1618
17
1066
18
7081
19
218
20
6927

544
10
828
10
100
9
52
9
634
9
177
10
10
10
704
5
887
10
815
9
53
9
141
10
859
7
26
10
935
10
8
6
105
8
989
10
290
9
952
10

455

? ,
10 ! ,
.

312

42
,

, , !
-, , .
, .
.
, . ? ,
. ,
, ! ,
.
, .
.
. - ,
.
( , ).
. , N
N . ,
, , N/2.
:
. . 7 ,
455, 1000/2.
. .
.
? , . ,
. , ,
N ,
. , , .
1. 1000 / 2 = 500
2. 500 / 2 = 250
3. 250 / 2 = 125
4. 125 / 2 = 62
5. 62 / 2 = 31
6. 31 / 2 = 15
7. 15 / 2 = 7
8. 7 / 2 = 3
9. 3 / 2 = 1

,
. 9 . ,
10 (
). ,
(. 7) !
313

42
,

. ,
10/2 = 5 ? ! ,
.
. ,
, 9. . 7, !
! ,
, :
.

? !
,
. :
.

( , !). :
, . ,
- : N .
.
Log2 N
N
.
, .
4 = 2 2

Log2 4 = 2

16 = 2 2 2 2

Log2 16 = 4

64 = 2 2 2 2 2 2

Log2 64 = 6

, (,
!), . ,
8 , . ,
, . ,
,
.
, . 8
.

314

42
,

. 8

Log2 N

Log2 N

Log2 N

Log2 N

32

512

8192

13

64

1024

10

16384

14

128

2048

11

32768

15

16

256

4096

12

65536

16

,
: ,
.
, , 50?
32 64, -
5 6? : 50 5,64 (
). ,
, .
? , 50 6. ,
33 64.
. 91, .
, .
(
!).

. 91
315

42
,

() ,
.
;
, .
:
.
( ) .
,
.
,
.
.

?
). ?
.
)
? ? .
) ,
. ,
, :
123 .., . , . 21, . 11-22-33
35 .., . , . 5, . 33-22-11

.
)
.
) .

,
. . , ,
, - . ,
, . :
() 5000? .
.

316

43
-
, , . ,
. ?
. ! ,
. ,
? !



. ?
, .
.
, (
). , .
, .
.
, .

. , .
, .
, ,
( ,
). , ,
, . ,
.
, , .
() , .
. (
) .
, . ,
N-1 , . , ,
, , , ,
?

317

43
-

Left

Right

. 92

, ,
?
, , ,
. , .
, .
SelectionSort
(Selection , Sort ). ,
,
.
. ,
, ?

{ P_43_1

SelectionSort

const CSize=10;

{ }

type TNumbers = array [1..CSize] of Integer;


var

Arr

: TNumbers;

{ }

{ }

318

43
-
{ }
procedure SelectionSort(var arg: TNumbers);
var

L, R, T: Integer;

begin
for L := 1 to CSize-1 do
{ }
for R := CSize downto L+1 do begin
{ ,
}
if arg[L] > arg[R] then begin
{ }
T:= arg[L];

arg[L]:= arg[R]; arg[R]:= T;

end;
end;
end;
{ , arg }
procedure ShowArray(const arg: string);
var i: integer;
begin
Writeln(arg);
for i:=1 to CSize do Writeln(Arr[i]);
Readln;
end;
var i: integer;
begin
{ }
for i:=1 to CSize do Arr[i]:=1+Random(1000);
ShowArray(' :');
SelectionSort(Arr);
ShowArray(' :');
end.


- , ,
, , ? !
!.
.
, , .
319

43
-

,
. , , .
. , ,
. , ,
. !
, , .
, :
!. (. 92).
! , !
.
,
. .
? ,
? , !
, , ,
.
?
! , !
, , , ? .
, .
? , !
?
, , , .
.
, , , .
, .
.
, , , ,
. ,
.
.
:
, ,
- .
.
320

43
-

,
, .
! . -,
!
-- , , , !
.


, .
, ?
, , ?
,
, .
. !
! ,
.
, . ,
. , 1/3 2/3
. ,
( ).
: , ,
.
.
:= ([L] + [(L + R)/2] + [R]) / 3;

L R
. ,
.

321

43
-

,
, ,


.

. 93

,
QuickSort (Quickly , Sort ).
.

322

43
-
{ P_43_2

QuickSort

const CSize=10;

{ }

type TNumbers = array [1..CSize] of Integer;


var

Arr

: TNumbers;

{ }
procedure QuickSort(var arg: TNumbers; aL, aR: Integer);
var
L, R : integer; { }
M, T : Integer; { }
begin
{ }
L:= aL;

R:= aR;

{ ( ) }
M:= (arg[L] + arg[(L + R) div 2] + arg[R]) div 3;
repeat

{ }

{ ,
}
while arg[L] < M do L:=L+1;
{ ,
}
while arg[R] > M do R:=R-1;
{ }
if L <= R then begin
{ "", ,
,
}
if arg[L]>arg[R] then begin
t:= arg[L];

arg[L]:= arg[R]; arg[R]:= t;

end;
{ }
L:=L+1;

R:=R-1;

end;
until L > R; { "" }
{ , }
if R > aL then QuickSort(arg, aL, R);
{ , }
if L < aR then QuickSort(arg, L, aR);
{ }
end;

323

43
-
{ , arg }
procedure ShowArray(const arg: string);
var i: integer;
begin
Writeln(arg);
for i:=1 to CSize do Writeln(Arr[i]);
Readln;
end;
var i: integer;
begin

{--- ---}
{ }
for i:=1 to CSize do Arr[i]:=1+Random(1000);
ShowArray(' :');
QuickSort(Arr, 1, CSize);
ShowArray(' :');

end.

QuickSort.
, (aL) (aR)
().

.
,
. ,
QuickSort: ,
( ). ,
.
, !
? . ,
, , .
? , ?
?


.
? , ( , ).
, QuickSort
? ,
. (R > aL) (L < aR)
, ,
. ,
324

43
-

, .

!
:
? ,
.
, . ?
,
.
( ).
, ,
(Stack).
?
? . , ,
. :

.
, .

, .
,
, .
( ),
.
, ,
!
, .
! , .
P_43_2 .

, !
, ,
? :
BubbleSort
SelectionSort
QuickSort

,
,
.

. , :
, . 42- ,
325

43
-

, .
. , ?
. - ... ,
,
.
, , ,
(P_43_3).
C1 C2. EXTENDED,
. ?
,
, , ,
. EXTENDED.
,
.
(C1) (C2), . ,
.
.
Arr0,
Arr .

.

326

CSize,

43
-
{ P_43_3

- }

const CSize=100;

{ }

type

TNumbers = array [1..CSize] of Integer;

var

Arr0 : TNumbers;

{ - }

Arr

{ }

: TNumbers;

C1, C2 : extended; { }
{ BubbleSort "" }
procedure BubbleSort(var arg: TNumbers);
var

i, j, t: Integer;

begin
for i:= 1 to CSize-1 do
for j:= 1 to CSize-i do begin
C1:=C1+1; { }
if arg[j] > arg[j+1] then begin
C2:=C2+1; { }
t:= arg[j]; arg[j]:= arg[j+1];

arg[j+1]:= t;

end;
end;
end;
{ SelectionSort }
procedure SelectionSort(var arg: TNumbers);
var

L, R, T: Integer;

begin
for L := 1 to CSize-1 do
for R := CSize downto L+1 do begin
C1:=C1+1; { }
if arg[L] > arg[R] then begin
C2:=C2+1; { }
T:= arg[L];

arg[L]:= arg[R]; arg[R]:= T;

end;
end;
end;
{ QuickSort }
procedure QuickSort(var arg: TNumbers; aL, aR: Integer);
var
L, R, Mid, T: Integer;
begin
L:= aL;

R:= aR;

327

43
-
Mid:= (arg[L] + arg[(L + R) div 2] + arg[R]) div 3;
repeat
while arg[L] < Mid do begin L:=L+1; C1:=C1+1 end;
while arg[R] > Mid do begin R:=R-1; C1:=C1+1 end;
if L <= R then begin
if arg[L]>arg[R] then begin
C2:=C2+1; { }
t:= arg[L];

arg[L]:= arg[R]; arg[R]:= t;

end;
L:=L+1;

R:=R-1;

end;
until L > R;
if R > aL then QuickSort(arg, aL, R);
if L < aR then QuickSort(arg, L, aR);
end;
const CFName = 'P_43_3.out';
var i: integer;
F: text;
begin
Assign(F,CFName);

Rewrite(F);

for i:=1 to CSize do Arr0[i]:=1+Random(10000);


Writeln(F, ' = ', CSize);
Writeln(F, '

');

Writeln(F, '

');

C1:=0; C2:=0;

{ }

Arr:= Arr0;

{ }

BubbleSort(Arr);
Writeln(F, ':', C1:12:0, C2:12:0);
C1:=0; C2:=0;

{ }

Arr:= Arr0;

{ }

SelectionSort(Arr);
Writeln(F, '

:', C1:12:0, C2:12:0);

C1:=0; C2:=0;

{ }

Arr:= Arr0;

{ }

QuickSort(Arr, 1, CSize);
Writeln(F, '
Writeln('OK !');

:', C1:12:0, C2:12:0);

Readln;

Close(F);
end.

328

43
-

, 1000 .
= 1000

499500

248061

499500

80887

5871

2417

100, 1000 10000 ,


. ?
. 9

100

4 950

4 950

417

1 000

499 500

499 500

5 871

10 000

49 995 000

49 995 000

79 839

. 9 ,
. ,
10 600 ! ,
.
. 10

100

2 305

805

141

1 000

248 061

80 887

2 417

10 000

24 903 994

6 154 077

31 011

(. 10)? , 3- 4- .
.
! ,
. ,
!

329

43
-

BubbleSort

SelectionSort

QuickSort

. 94 ?

, (. 94), ?
. ,
, .

NN, N .
, .
. ,
.
, NLog2N.
? , .
, QuickSort (. 95).

NxN

N x Log2N
N

. 95

330

43
-

BubbleSort SelectionSort
.
QuickSort .
.

?
) (
).
.
) QuickSort
. , Level
. , QuickSort,
, .
QuickSort:
begin
Inc(Level); Writeln(' = ', Level);

QuickSort:
Dec(Level); Writeln(' = ', Level);
end;

) QuickSort ,
Level Log2N
( N CSize).
, CSize.

331

44

STRING ,
.
.
, ,
Borland Pascal.


, ;
. ? . ,
255 . 255
( ) . , SizeOf
, .
var

S1 : array [1..255] of CHAR; { 255 }


S2 : String;

{ 255 }

begin
Writeln (SizeOf(S1));

{ 255 }

Writeln (SizeOf(S2));

{ 256 }

Readln;
end.

? ? , S2
256 , . ?
? . 96.

255

. 96 PASCAL

332

44

PASCAL.
1- 6- , .
!
6 PASCAL. ,
, (
Length).


- .
( ) 256 ,
. ,
. : 256 ,
? ,
. , ,
, 20 .
,
. ,
255. STRING
, .
type
var

TStrA = string[11];

{ 11 }

TStrB = string[31];

{ 31 }

A : TStrA;

B : TStrB;

; 11
, 31. A
12 , B 32 ( ). ,
, . ,
, STRING.
? ,
.
P_44_1 , .

333

44

{ P_44_1
var

- }

S1 : string;

{ = 255 }

S2 : string[5];

{ = 5 }

begin
S1:='abc';

S2:='abcdefgh';

Writeln(' S1:

=', SizeOf(S1):4,'

Length(S1):4,'
Writeln(' S2:

= '+S1);

=', SizeOf(S2):4,'

Length(S2):4,'

= ',
= ',

= '+S2);

Writeln(' S1 = ', Byte(S1[0]));


Writeln(' S2 = ', Byte(S2[0]));
Readln;
end.


, ,
. ? :
;
();
Length;
;
( ).
,
, :
;
;
;
;
.
.
, .
(Pos)
Pos , .

334

44

function Pos(S1: string; S2: string): Integer;

:
S1 , ( );
S2 , .
S1 ,
S1 S2. .
S2 ,
. .
S:= 'BORLAND PASCAL';
p:= Pos('LA', S);

{ 4 }

p:= Pos('PAS', S);

{ 9 }

p:= Pos('pas', S);

{ 0 }

p:= Pos('A', S);

{ 5 "A" }

.
; , P
.
(Copy)
Copy .
function Copy(S: string; Index, Count: Integer): string;

:
S , ;
Index ;
Count .
.
S:= Borland Pascal forever!;
T:= Copy(S, 8, 6);

{ Pascal }

T:= Copy(S, 8, 255);

{ Pascal forever! }

, ,
( ).
335

44

(Insert)
.
? Insert.
procedure Insert(S1: string; var S2: string; Index: Integer);

:
S1 ;
S2 ;
Index .
.
S:='!';
{ 7 : }
Insert(' ', S, 7);

{ ! }

S2, S1
S2. S2 ,
.
(Delete)
: . , ,
. ? Delete .
procedure Delete(var S: string; Index, Count : Integer);

:
S ;
Index ;
Count .
.

336

44

S:= Borland Pascal forever!;


Delete(S, 8, 7);

{ Borland forever! }


( ).
.
, ( ),
, .
Writeln (Borland > Pascal);

{ false }

Writeln (ABC > AB);

{ true }

Writeln (ABC > abc);

{ false }

B P,
. ,
, . ,
.
, (
). ,
.
( DELPHI ).
(Upase)
Upase ,
. ,
. .
function UpCase(Ch: Char): Char;

, ,
, .
c:= UpCase(r);

{ R }

c:= n;
c:= UpCase( c );

{ N }

,
, .
Upase.

337

44

c:= UpCase(R);

{ R }

c:= UpCase(8);

{ 8 }

c:= UpCase();

{ }

Upase
. ,
, .
, , .


, Pascal.
, Pos,
.
, ?
. , ,
. P_44_2.
{ P_44_2 var

PASCAL }

S : string;

{ }

p : integer;

{ }

c : integer;

{ }

begin
S:=' PASCAL!'+
' PASCAL! PASCAL !';
c:=0;
repeat
p:= Pos('PASCAL', S);

{ PASCAL }

if p>0 then begin

{ }

Inc(c);

{ }

{ }
Delete(S, p, Length('PASCAL'));
end
until p=0;

{ , PASCAL }

Writeln(' PASCAL: ',c);

Readln;

end.


,
. .
, , Pascal.
Pascal ( - ?).
338

44

, .
(P_44_3).
{ P_44_3 var

Pascal }

S : string;

{ }

p : integer;

{ }

begin
S:=' Pascal! '+
' Pascal! Pascal !';
Writeln(S); { }
repeat
p:= Pos('Pascal', S);
if p>0 then begin

{ 'Pascal' }
{ }

{ }
Delete(S, p, Length('Pascal'));
{ ''}
Insert('', S, p);
end
until p=0;

{ , 'Pascal' }

Writeln(S); { }
Readln;
end.

.
.
, , 255
, 256 .
.
( ,
STRING).
,
.

?
) , (
) .
)
( ). : .

339

44

) .
) , ,
. , :
MyCopy, MyDelete .

340

45

. ,
, .
, .
! , ,
.
, . !
? ? !
.



. , ,
, : ?
?
: ,
. : , ?.
. : ,
. - . ,
. ,
. ? ,
. , . ,
. ,
.
,
. LIFO,
Last-In, First-Out, -:
. ,
. ? :
. , , ,
.
, ,
.
?
? , ,
. ,
. ,
.
341

45

.
,
. ,
.
FIFO,
First-In, First-Out , . ,
.
, :
, .
.


.
.
,
.
, , .
, .
, .
,
, , . ,
.
, ( ),
. ,
, .
,
. , ,
, - .
: ,
( , ).

. 97
342

45

: ,
, , , ,
.
. :
,
. ,
ZHJKqwertASDyuiopQWERTYUIOPasdf

, Z,
f. Z q.
, .
, , .
,
. ,
, :
, . . ,
, .
Zq Hw Je Kr At Sy Du Qi Wo Ep Ra Ts Yd Uf

,
. I, O P.
, , :
? ,
, .
.
: ,
( ) .
PutInQue GetFromQue
( Queue ).
P_45_1.

343

45

{ P_45_1

- }

{ arg Que }
procedure PutInQue(var Que: string; arg: char);
begin
Que:= Que + arg;

{ }

end;
{ Que arg }
function GetFromQue(var Que: string;
var arg: char): boolean;
begin
if Length(Que) = 0

{ }

then GetFromQue:= false


else begin
GetFromQue:= true;

{ }

arg:= Que[1];

{ }

Delete (Que, 1, 1);

{ }

end
end;
{ }
var

S_IN : string;

{
}

S_OUT : string;

{ () }

Boys

{ }

: string;

Girls : string;

{ }

c1,c2 : char;

{ }

i : integer;

{ }

begin {--- ---}


{ : A..Z , a..z }
S_IN:='ZHJKqwertASDyuiopQWERTYUIOPasdf';
{ }
S_OUT:='';
{ }
Boys:='';

Girls:='';

344

45

{ }
for i:=1 to Length(S_IN) do begin
c1:= S_IN[i];

{ }

if c1 in ['A'..'Z']
then begin { ...}
{ }
if GetFromQue(Girls, c2)
{ }
then S_OUT:= S_OUT+c1+c2+
{ }
else PutInQue(Boys, c1);
end
else begin { ...}
{ }
if GetFromQue(Boys, c2)
{ }
then S_OUT:= S_OUT+c2+c1+
{ }
else PutInQue(Girls, c1);
end
end;
Writeln(' :' );
Writeln(S_IN);
Writeln(' :' );
Writeln(S_OUT);
if Length(Boys)>0 then begin
Writeln(' :' );
Writeln(Boys);
end;
if Length(Girls)>0 then begin
Writeln(' :' );
Writeln(Girls);
end;
Readln;
end.

PutInQue .
, 255 ,
. ,
, .
345

45

GetFromQue, ,
, .
, (TRUE,
).
arg, . , ,
. . ,
.


, , .

? , , !
. 98.

. 98

,
, . ,
1 (
). ,
. !
.
1, ;
. ,
,
. .
, .
, ,
. !
, .

346

45


, ,
.
. ;
, .
, .
, ,
. ,
. , .
,
(. 99).

. 99

? :
(, !).
,
,
. ,
.
,
, ,
.
, ,
. ; ,
.
, .
, . ,
,
, .

347

45

, .
(), . ,
AZ, A; ,
az, B, ,
09, C.
.
, , .

.
. , .
: ,
.
: Push Pop
.
Push .
-- ,
.
Pop ,
. ,
. ,
: ,
.

P_45_2. :
Pop,
.

348

45

{ P_45_2

{ }
procedure Push(var aStack: string; arg: char);
begin
aStack:= aStack + arg;

{ }

end;
{ }
function Pop(var aStack: string; var arg: char): boolean;
begin
if Length(aStack) = 0
then

Pop:= false

else

begin

{ }
{ }

{ }
arg:= aStack[Length(aStack)];
{ }
Delete(aStack, Length(aStack), 1);
Pop:= true; { , }
end;
end;
var

S : string;

{ }

SA, SB, SC : string;

{ A,B,C}

c : char;

{ }

begin
{ : }
S:= 'HEjd31kDJK62px912se3BKdwL9';
Writeln(' :

'+S);

{
}
while Pop(S, c) do begin
if c in ['A'..'Z'] then Push(SA, c);
if c in ['a'..'z'] then Push(SB, c);
if c in ['0'..'9'] then Push(SC, c);
end;
{ , S='' }
{ A }
while Pop(SA, c) do Push(S, c);
Writeln(' A
S:='';

'+S);

{ }

349

45

{ B }
while Pop(SB, c) do Push(S, c);
Writeln(' B
S:='';

'+S);

{ }

{ C }
while Pop(SC, c) do Push(S, c);
Writeln(' C

'+S);

Readln;
end.

.
, ,
.

, .
.

FIFO (First-In, First-Out).

LIFO (Last-In, First-Out).

?
) , ,
. ,
, .
? , .
: ,
, . , ,
? .
)
. ()
, .
: .
) ,
. ?

350

46

,
,
...

?
,
, , .
,
, , ,
! ,
.
, !
,
, .
LongInt .
2.147.483.647, .
, , .
Extended,
104932 ! ,
! ;
Extended , . ,
( ).
, , .
? . :
.
, ,
( ! ).
!


.

. : , ,
?. ,
? . 100 .

351

46

+
3

. 100

, ,
. ,
10 ( 0 9),
.
A B,
.
:= (A + B + ) mod 10
:= (A + B + ) div 10

, MOD
, DIV .
.
, !


,
.
: , 0 9,
09. ,
, 255 ,
.
,
P_46_1,
.

352

46

{ P_46_1 }
{ }
const CSize = 500;

{ }

type

TBigNumber = array [1..CSize] of char;

var

BN : TBigNumber; { ! }
{
.
, .
" ".
, , .}

procedure WriteBigNumber(var F: text; const aNum: TBigNumber);


var i : integer;
begin
i:= SizeOf(aNum); { }
{ , }
while (i>0) and not (aNum[i] in ['1'..'9']) do Dec(i);
{ , }
if i=0 then Write(F, '0');
{ }
while i>0 do begin
Write(F, aNum[i]);
Dec(i);
end;
{ }
Writeln(F); Writeln(F);
end;
var

i : integer;

begin

{ === === }

FillChar(BN, SizeOf(BN), ' ');

{ }

WriteBigNumber(Output, BN);
FillChar(BN, SizeOf(BN), '7');

{ }

WriteBigNumber(Output, BN);
{ }
for i:=1 to CSize-1 do BN[i]:= Char(Random(100) mod 10 + Ord('0'));
WriteBigNumber(Output, BN);
Readln;
end.

, TBigNumber , ,
500 . WriteBigNumber
, . ,
Dec(i) .
353

46

FillChar
. ,
FillChar , .
procedure FillChar(var X; Count: Integer; Value: Byte);

X, ,
! .
Count , X.
Count
SizeOf(X). , , Value ,
. ( ),
, ,
. .
var

A : array 1..100 of char;


B : array 1..200 of byte;
: array 1..50 of boolean;

. . .
FillChar(A, SizeOf(A), *);

{ }

FillChar(B, SizeOf(B), 0);

{ }

FillChar(C, SizeOf(C), false);

{ }

, .
. WriteBigNumber
, .
Output, ,
. Output , ,
.
Input .


, ,
.
,
AddNumbers .
, .
,
.
09, 09,
(
). .
354

46

:= Ord (_) Ord (0)
_ := Char (Ord (0) + )

.
{ P_46_2 }
{ }
const CSize = 500;

{ }

type

TBigNumber = array [1..CSize] of char;

var

BN1, BN2 : TBigNumber; { }

{ }
procedure WriteBigNumber(var F: text; const aNum: TBigNumber);
var i : integer;
begin
i:=CSize;
while (i>0) and not (aNum[i] in ['1'..'9']) do Dec(i);
if i=0 then Write(F, '0');
while i>0 do begin
Write(F, aNum[i]);
Dec(i);
end;
Writeln(F); Writeln(F);
end;
{ " ".
,
aNum1 := aNum1 + aNum2 }
procedure AddNumbers(var aNum1, aNum2 : TBigNumber);
var

i,j : integer;
n1, n2 : integer;

{ }

sum, ovr : integer;

{ }

355

46

begin
ovr:=0;

{ = 0 }

{ , }
for i:=1 to CSize-1 do begin
j:=i;

{ j }

{ , ,
0..9 }
if aNum1[i]=' '
then n1:=0
else n1:=Ord(aNum1[i])-Ord('0');

{ n1 = 0..9 }

if aNum2[i]=' '
then n2:=0
else n2:=Ord(aNum2[i])-Ord('0');

{ n2 = 0..9 }

sum:= (n1+n2+ovr) mod 10;

{ sum = 0..9 }

ovr:= (n1+n2+ovr) div 10;

{ ovr = 0 1 }

{ }
aNum1[i]:= Char(sum + Ord('0'));
end;
{ , }
if ovr<>0 then aNum1[j+1]:='1';
end;
var

i : integer;

begin

{ === === }

FillChar(BN1, SizeOf(BN1), ' ');


FillChar(BN2, SizeOf(BN2), ' ');
for i:=1 to CSize-1 do BN1[i]:= Char(Random(100) mod 10 + Ord('0'));
for i:=1 to CSize-1 do BN2[i]:= Char(Random(100) mod 10 + Ord('0'));
WriteBigNumber(BN1); { }
WriteBigNumber(BN2); { }
AddNumbers(BN1, BN2);
WriteBigNumber(BN1); { }
Readln;
end.

,
? .
.

356

46

(499 ):
88034474755263463811157748177169236752040135153256253684350812170455816590318
00071999794366118265182563758720378673660135839398953141512906024942788294156
87161839916961209398611500546931200667866376204115538852965830795649105020542
39766629218650967805390582667595078756176058697083583183449492998242422080009
29286578540423001609560508264356930728328745107168941254697109511365727966941
14943180905784305897765764767829886881494780038570897897494598050757092044228
9778748724626014927619547782761770630

(499 ):
43010563208133392591277430216910724399992657359176370031800475954810286799180
94988721008241589616753155174586670761982847129881691883312995998642786642828
13634112956964635790325217557777821776772170919033280201619190732499393489224
79685741671026466238595732664573620249024113167965874496798091533936733068022
89884085958345033422404931451426067305519212005730606726274258487491929559866
58127808673232802597523028091073608068168675926089639207972222781877706192312
8832709593717254099272079488419978116

(500 ):
13104503796339685640243517839407996115203279251243262371615128812526610338949
89506072080260770788193571893330704943564298296928064502482590202358557493698
50079595287392584518893671810470902244463854712314881905458502152814849850976
71945237088967743404398631533216869900520017186504945768024758453217915514803
21917066449876803503196543971578299803384795711289954798097136799885765752680
77307098957901710849528879285890349494966345596466053710546682083263479823654
18611458318343269026891627271181748746

,
, !


. .
, ,
.
FillChar
.
Input ( ) Output (
) .
357

46

, ,
, .

?
)
( 200).
) . ?
!

358

47

,
, .


? .
.
! ,
!
?
, , .
(,
). ? !
.
, .
1, 2, 3 .
0. , , ,
:
, . ,

15-16 !
,
: ? ,
, !.
, .


, ? -
, ,
. ?
,
. ? . 101, .
, -, .
,
. : , !

359

47

Twelve -

12

111111111111

1100

0h

$0

. 101 12

, , .
: , ,
. , ,
. ,
.
(). Writeln
, , ,
. ,
Writeln ,
. , :
, .
,
. Readln, .
,
. ,
(, ).
, , .

360

47


:
, , . , 2048
.
2048 = 2 1000 + 0 100 + 4 10 + 8 1
.
2048 = 2 103 + 0 102 + 4 101 + 8 100
, ,
, .
:
. ? ?
, .
,
, .
_ := MOD 10

.
, ,
.
_ := DIV 10

, . 102.

361

47

N mod 10

N div 10

. 102

, .
,
. .
var N : integer;
begin

S : string;

{ }

Write('N= '); Readln(N);


S:='';
repeat
S:= Char((N mod 10)+Ord('0')) + S;

{ }

N:= N div 10;

{ }

until N=0;
Writeln(S);

Readln;

end.

, ,
.
? .
2048 = 2 1000 + 0 100 + 4 10 + 8 1 = (((0 10+2) 10+0) 10+4) 10+8
,
. ,
, 10.
362

47

010.
, ,
. 103.

0

N = 0

2
10

+2

2
+0
10
2

+4

0
10

N=2048

+8

4
10

. 103

, 2048 :
N = 0 -
N = 0 10 + 2 = 2
N = 2 10 + 0 = 20
N = 20 10 + 4 = 204
N = 204 10 + 8 = 2048

, .

363

47

var N : integer;

i : integer;

S : string;

begin
Write('S= '); Readln(S);
N:=0;
for i:=1 to Length(S) do
Writeln(N);

N:= 10*N + Ord(S[i]) Ord ('0');

Readln;

end.

,
, .
.



, .
.
.
.
, : .
, ,
, .
,
(
?). 0,
1. , .
, ? .

. , ,
. ,
1, 2, 4, 8 , 2. , 12
(. 104).

3

12 = 1 8 + 1 4 + 0 2 + 0 1

. 104 12
364

47

, ,
.
, . ,
(0 1) . ,

.
, .
:
B ( Binary ),
. , 12 .
1100B

1100b

11002


,
. ,
, .
4005 = 1111101001012
, - .
:
( Tetra ).
, .
, 4005 .
4005 = 1111101001012 1111.1010.01012 15.10.05
0 15 16 ,
.
, 10 15 :
A=10
B=11
C=12
D=13
E=14
F=15

: 15.10.05 FA5
. 105 .
365

47

1111.1010.0101 2

15

10

. 105

,
, .
: ,
H ( Hex ). ,
FA0 :
0FA5H

0FA5h

.
0x (0xFA5),
$ ($FA5).
?
.
.

. , - ,
.
.

366

47

. 11

0
8

1000

1001

10

1010

0011

11

1011

0100

12

1100

0101

13

1101

0110

14

1110

0111

15

1111

0000

0001

0010


, :
, . ?
!
, .
2048 = 2 103 + 0 102 + 4 101 + 8 100

- ;

12 = 11002 = 1 23 + 1 22 + 0 21 + 0 10 - ;
2000 = $FA0 = F 162 + A 161 + 0 160

- .

, , .
, , ,
. , .
? , ,
, !
:
( 2 16).


,
, .
, .
,
MOD 2, DIV 2.
MOD 16 DIV 16.
: N-
367

47

MOD N,
DIV N.
P_47_1 ConvertFromNumber
, .
.
const CDigits : string = '0123456789ABCDEF';

015

0F. , ,
, .
{ P_47_1 }
{ }
function ConvertFromNumber(aBase, aNumber : integer): string;
const CDigits : string = '0123456789ABCDEF';
var n : integer;

c : char;

S : string;

begin
S:=''; { }
repeat
n:= aNumber mod aBase;

{ }

aNumber:= aNumber div aBase; { }


c:= CDigits[1+n];

{ }

Insert(c, S, 1);

{ }

until aNumber=0;
ConvertFromNumber:= S; { ! }
end;
var B, N : integer;

{ B j , N }

begin {=== ===}


repeat
Write(' = '); Readln(B);
if B in [2..16] then begin
Write(' = '); Readln(N);
Writeln(ConvertFromNumber(B, N));
end
until not (B in [2..16]);
end.


, , .
368

47


: ,
;
.
.
,
. ,
? ,
.
ConvertToNumber .
{ P_47_2 }
function ConvertToNumber(aBase: integer; aNumber: string): integer;
var

i,n, Sum : integer;


c : char;

begin
Sum:=0; { }
for i:=1 to Length(aNumber) do begin
c:= Upcase(aNumber[i]);
if c in ['0'..'9']
then n:= Ord(c)-Ord('0')

{0..9}

else n:= 10+Ord(c)-Ord('A');

{10..15}

Sum:= aBase*Sum + n;

{ }

end;
ConvertToNumber:= Sum; { ! }
end;
var

B : integer;

{ }

N : string;

{ }

begin {=== ===}


repeat
Write(' = '); Readln(B);
if B in [2..16] then begin
Write(' = '); Readln(N);
Writeln(ConvertToNumber(B, N));
end
until not (B in [2..16]);
end.

, , .
UpCase . ,
369

47

A F
, .
,
UpCase.
. 0 9
0. A F
A 10.
.
if c in ['0'..'9']
then n:= Ord(c)- Ord('0')

{0..9}

else n:= 10 + Ord(c)- Ord('A');

{10..15}

, , .
, !


.
.
. ,
.
( )
, .

?
)
. :
;
;
.

ConvertFromNumber.

ConvertToNumber

) ,
. ,
.
( ). ,

370

47

, ( 001 999),
N ( N ).
) . , 45
. :
, .
?
) .
,
,
.

371

48

,
, .


,
. 8, 16, 32 64 ,
1, 2, 4 8 .
-.
? , (. 106).
, ,
. , 8- Byte,
16- Integer Word, 32- Longint.
, , .
, ,
.
, .
,
, .

. 106

372

48


, .
var

A, B, C : integer;

begin
A:= 5;

B:=16;

C:= A or B;

Writeln( C );
end.

C
. ,
? , .
! 0 1,
FALSE TRUE. ,
.
, 16 .
.
, BOOLEAN ,
, , ?
8 , 16,
32. .
,
.
, , , . !
.

, . P_48_1
ConvertFromNumber.
,
. ,
.
ConvertTo2, P_48_1.

373

48

{ P_48_1 }
{ }
function ConvertTo2(aNumber : integer): string;
var n, i : integer;

c : char;

S : string;

begin
S:=''; { }
for i:=1 to 8 do begin
n:= aNumber mod 2;

{ }

c:= Char(n + Ord('0'));

{ }

S:= c + S;

{ }

aNumber:= aNumber div 2;

{ }

end;
ConvertTo2:= S;
end;
var A, B, C : byte;

{ }

begin {=== ===}


repeat
Write('A= '); Readln(A);
Write('B= '); Readln(B);
C:= A or B;

{ () }

Writeln;
Writeln('C= A OR B');
Writeln('A= ',ConvertTo2(A), A:5);
Writeln('B= ',ConvertTo2(B), B:5);
Writeln('C= ',ConvertTo2(C), C:5);
C:= A and B;

{ () }

Writeln;
Writeln('C= A AND B');
Writeln('A= ',ConvertTo2(A), A:5);
Writeln('B= ',ConvertTo2(B), B:5);
Writeln('C= ',ConvertTo2(C), C:5);
C:= not A;

{ () }

Writeln;
Writeln('C= NOT A');
Writeln('A= ',ConvertTo2(A), A:5);
Writeln('C= ',ConvertTo2(C), C:5);
end.

:
, ,
. ,
, .
374

48

C= A OR B
A= 00001101

13

B= 00001011

11

C= 00001111

15

C= A AND B
A= 00001101

13

B= 00001011

11

C= 00001001

C= A XOR B
A= 00001101

13

B= 00001011

11

C= 00000110

C= NOT A
A= 00001101

13

C= 11110010

242


(. 12).
, .
. 12

()

()

1010
1100
1110

OR

,
.

AND

,
.

1010
1100
1000
1010

XOR

1100
()
0110

()

1010
NOT
0101

,
.

,
.

TRUE, FALSE,
.

375

48


,
.
: (SHL) (SHR).
(. 107)
, ,
, .
N:= 3;

{ 3 =

00000011 }

Writeln (N shl 1);

{ 6 =

00000110 }

Writeln (N shl 2);

{ 12 = 00001100 }

. 107

(. 108)
. ,
.
N:= 3;

{ 3 = 00000011 }

Writeln (N shr 1);

{ 1 = 00000001 }

Writeln (N shr 2);

{ 0 = 00000000 }

. 108

,
. TestBit,
: ARG , , BIT
376

48

. TRUE,
, FALSE .
function TestBit (arg: longint; bit : byte): Boolean;
begin
TestBit := (arg and (1 shl bit)) <> 0
end;

.
,
TRUE FALSE, 0 1.
, .
8, 16, 32 64 .

. .

?
) (
P_48_1).
) ,
() . (. 109)
, (
) ( ).

. 109

.
. :
,
.

377

49

,
. .


(38- ),
. ,
, . ,
,
.
,
. ,
. , . ,
, ,
, ? ,
. , .

.
, .
, .
, ,
.
. , ,
.


.
, , !
.
, .
. ,
. : , ,
, !
?
. .
, ,
. .
.

, ! ,
378

49

,
. . 110,
D,
A, C E, , B, I F.

1
16

27

28

I
26

13

15

14

17

30

18

31

19

20
25

29

12

21

22
23

11
24
10

- (D)
- (A, C, E)
- (B, I, F)
. 110

, , ? .
,
, ,
. , ,
. ,
,
.

379

49

, ! , .
, . ,
. 38-
-.
, ,
. , . ,
. TStates.
type

TBoundSet = set of 1..255;

{ }

TStates = array ['A'..'Z'] of TBoundSet; { }


var

States : TStates;

{ }

, ?
. ,
, .
, X,
States .
B:= States[X];

{ X = A...Z - }

?
! Succ. ,
, .
X:= A;
X:= Succ(X);

{ X = B }

X:= Succ(X);

{ X = C }

, .
, ,
, .
REPEATUNTIL,
.
, , P_49_1
Temp ( ).
EmpireB ,
!

Temp.
Temp:= EmpireB;

{ }

P_49_1 .
380

49

{ P_49_1 }
type

TNameRange= 'A'..'Z';

{ }

TNameSet = set of TNameRange; { }


TBoundSet = set of 1..255;

{ }

{ TStates }
TStates = array ['A'..'Z'] of TBoundSet;
{

() }

procedure ReadSet(var aFile: text; var aSet : TBoundSet);


var k : integer;
begin
while not Eoln(aFile) do begin
Read(aFile, k);
aSet:= aSet+[k];
end;
Readln (aFile);
end;
{ }
var

FileIn : text;

{ , }

States : TStates;

{ }

Names

{ }

: TNameSet;

C1, C2 : char;

{ "" "" }

{ }

: char;

EmpireB: TBoundSet;

{ }

Temp

{ }

: TBoundSet;

EmpireN: TNameSet;

{ }

Counter: integer;

{ () }

begin

{--- ---}

{ ( 36) }
Assign(FileIn, 'P_36_3.in'); Reset(FileIn);
{ }
Names:=[];

{ }

C:= 'A';

{ }

381

49

while not Eof(FileIn) do begin

{ }

ReadSet(FileIn, States[C]);

{ }

Names:= Names+[C];

{ }

C:= Succ(C);

{ }

end;
Close(FileIn);

{ }

repeat { }
Write(': '); Readln(C1);
Write('

: '); Readln(C2);

{ }
C1:= UpCase(C1);

C2:= UpCase(C2);

{ , ,
, }
if (C1<>C2) and (C1 in Names) and (C2 in Names)
then Break
else Writeln('! ');
until False;
{ }
EmpireB:= States[C1]; { C1 }
EmpireN:= [C1];

{ }

Counter:= 0;

{ " " }

{ , C2 }
repeat
{ " " }
C:='A';

{ }

Temp:= EmpireB;

{ }

{ " " }
while C in Names do begin
{ , }
if (Temp * States[C]) <> [] then begin
EmpireB:= EmpireB + States[C];

{ }

EmpireN:= EmpireN + [C];

{ }

end;
C:= Succ(C);
end;

{ }

{ }

Inc(Counter);

{ " " }

until C2 in EmpireN; { C2 }
{ }
Writeln(' : ', Counter); Readln;
end.

382

49

. , ,
, .
, , ? ,
,
. , ,
, ! , ,
!

-
?
, ,
. ,
?
:
( ),
(. 111).

. 111

, , ,
.
, , ,
. . 112,
F.

383

49

0000000000000000000000000000000000000000
000000000000000000000000000+++++00000000
000000000000000000000000000+000000000000
000000000000000000000000000+000000000000
000000000000000000000000000+++++00000000
000000000000000000000000000+000000000000
000000000000000000000000000+000000000000
000000000000000000000000000+000000000000
0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
0000000000000000000000000000000000000000

. 112 ,
F

, .
25 80 .
20 40 .
20- 21- ,
10- 11- .
, :
, .
, .
, .
,
. ?
800 (20 40 ). , ,
? , (Desk) .
type

TDesk = array [1..800] of Boolean;

, 40
, 40 , .
, ?
: TLine
40 .

384

49

type

TLine = array [1..40] of Boolean;

20 ,
.
type

TDesk = array [1..20] of TLine;

.
type

TDesk = array [1..20] of array [1..40] of boolean;

.

.
type

TDesk = array [1..20, 1..40] of boolean;

, ,
. .
,
, . , Desk,
5- 3- , .
Desk[5, 3]

, ,
.
, ,
. ,
FALSE.
const Cx = 40;
Cy = 20;

{ () }
{ () }

type

TDesk = array [1..Cy, 1..Cx] of boolean; { }

var

Desk : TDesk;

{ }

Cx Cy.
FALSE .
for y:=1 to Cy do
for x:=1 to Cx do Desk[y, x]:= False;


FillChar.
385

49

FillChar(Desk, SizeOf(Desk), false);

SizeOf(Desk) 800
.
.
, TRUE 5- .
for y:=1 to Cy do Desk[y, 5] := True;

3- .
for x:=1 to Cx do Desk[3, x] := True;

,
P_49_2.
ReadDesk, .
, Desk TRUE,
FALSE. :
S,
( ,
?).
Desk[y,x]:= S[x]='+';

{ TRUE, S[x] }

, :
.
WriteDesk,
. 40 ,
.
, CSymbols.
const CSymbols : string = '0+';

.
S:= S + CSymbols[1+ Ord(Desk[y, x])];

, Desk[y,x], FALSE,
, TRUE ,
.

386

49

if Desk[y, x]
then S:= S + CSymbols[2]
else S:= S + CSymbols[1]


,
.
,
. ,

. (1, 2 3),
-, .
.
{ P_49_2 "-" }
const Cx = 40;
Cy = 20;

{ () }
{ () }

type

TDesk = array [1..Cy, 1..Cx] of boolean;

var

Desk : TDesk;
{ }

procedure ReadDesk(var F: Text);


var

x, y: integer;

{ x , y }

S: string;
begin
FillChar(Desk, SizeOf(Desk), false);
y:=1;
while not Eof(F) and (y<=Cy) do begin
Readln(F, S);
x:=1;
while (x<=Length(S)) and (x<=Cx) do begin
Desk[y,x]:= S[x]='+';
Inc(x);

{ x:= x+1 }

end;
Inc(y);

{ y:= y+1 }

end
end;

387

49

{ }
procedure WriteDesk(var F: Text);
const CSymbols : string = '0+';
var

x, y: integer;

S: string;

begin
for y:=1 to Cy do begin
S:='';
for x:=1 to Cx do S:= S + CSymbols[1+ Ord(Desk[y, x])];
Writeln(F, S);
end;
end;
{ }
procedure Swap (var a, b : boolean);
var t : boolean;
begin
t:=a;

a:=b;

b:=t;

end;
{ }
procedure Vert;
var x, y: integer;
begin
for y:=1 to Cy do
for x:=1 to Cx div 2 do Swap(Desk[y, x], Desk[y, Cx-x+1])
end;
{ }
procedure Horisont;
var x, y: integer;
begin
for y:=1 to Cy div 2 do
for x:=1 to Cx do Swap(Desk[y, x], Desk[Cy-y+1, x])
end;
{ }
procedure Invers;
var x, y: integer;
begin
for y:=1 to Cy do
for x:=1 to Cx do Desk[y, x]:= not Desk[y, x]
end;

388

49

var

FileIn : Text;
cmd : integer;

begin

{=== ===}

Assign(FileIn, 'P_46_2.in'); Reset(FileIn);


ReadDesk(FileIn);
Close(FileIn);
repeat
WriteDesk(Output);

{ }

Writeln;
Write('1- ; 2- ; 3- , 0- : ');
Readln(cmd);

{ }

case cmd of
1: Vert;

{ }

2: Horisont;

{ }

3: Invers;

{ }

else Break;

{ }

end;
until cmd=0;
end.

CSymbols.
const CSymbols : string = '0+';

, .
, ,
. , , ! !

, ,
, .
.
:
, .

389

49

?
)
,
. P_49_1 ,
. ?
) ,
.
.
) 38-
. , (256),
, , .
. , ,
. , , 1000 .
const CSize = 1000;
type

TBoolSet = array [1..CSize] of Boolean;

var

BS : TBoolSet;

, , FALSE,
. , , A B,
BS[A] BS[B] TRUE.
(
S).
FillChar(BS, SizeOf(BS), false);

{ S:= [] }

FillChar(BS, SizeOf(BS), true);

{ S:= [1..N] }

BS[N]:= true;

{ S:= S + [N] }

BS[N]:= false;

{ S:= S - [N] }

if BS[N] then

{ if N in S then }


1000 ( ). ?

390

50

!
, .
: ,
, . , !
, , , , .
, : , ,
, . ,
, ? ?
, 41.
.
: , .
( P_41_3).
(
, , ),
.
. !
,
, .
,
. -
!

.
, - RECORD. , ?
, . , ,
,
: , , .
.
. ,
, .
RECORD...END
, .
, .
, Team .
, .

391

50

type

Team = record

{ }

Aces

: integer;

{ }

Name

: string;

{ }

end;
var

Team1, Team2 : Team;

{ }

, RECORD END
Aces Name. ? , . , ,
TYPE . , ,
Team1 Team2 ( VAR)
Aces Name.
Team1 Team2.
, ?
,
. Team1.
Team1.Aces := 25;
Team2.Name := Dinamo;

, .
(
Team1 Team2). , ,
.
, ,
. ? ,
, , .
Team2 := Team1;

{ Team1 Team2 }

, .

, ,
.


, .
P_41_3,
. P_50_1,
( ) .
. .
.
392

50

type

TTeam = record
mAces : integer;

{ }

mName : string;

{ }

end;

,
T.
(Team) TTeam.
.
, m ( Member
). mAces mName.
TChamp (Champ )
.
TChamp = array [1..CSize] of TTeam;

{ }

,
: mAces mName.
TChamp .
var

Champ : TChamp;

{ }

Champ .
Champ[i]

i- ( TTeam), i-

Champ[i].mAces

i-

Champ[i].mName

i-

P_50_1 .

393

50

{ P_50_1

( 2) }

const CSize = 4; { }
{ }
type

TTeam = record
mAces : integer;

{ }

mName : string;

{ }

end;
TChamp = array [1..CSize] of TTeam;
var

Champ : TChamp;

{ }

{ }

{ "" }
procedure BubbleSort(var arg: TChamp);
var

i, j : Integer;
t : TTeam;

{ }

begin
for i:= 1 to CSize-1 do

{ }

for j:= 1 to CSize-i do

{ }

{ ...}
if arg[j].mAces < arg[j+1].mAces then begin
{ }
t:= arg[j];

{ }

arg[j]:= arg[j+1];

{ -> }

arg[j+1]:= t;

{ -> }

end;
end;
var i: integer;
begin

{--- ---}

{ }
for i:=1 to CSize do begin
Write(' : '); Readln(Champ[i].mName);
Write(' :

'); Readln(Champ[i].mAces);

end;
BubbleSort(Champ);

{ }

{ }
Writeln(' :');
Writeln('

');

for i:=1 to CSize do begin


Writeln(i:3,' ':3, Champ[i].mName,
Champ[i].mAces:(20-Length(Champ[i].mName)) );
end;
Readln;
end.

394

50

. !
, .
( ) TTeam.
.
, :
( ).
.
20-Length(Champ[i].mName)


, .


, .
, .
, ,
, .
, , , .
,
TTeam .
type

TTeam = record
mAces : integer;

{ }

mName : string;

{ }

mWins : integer;

{ }

mFails: integer;

{ }

end;

Champ ,
.
BubbleSort , !
P_50_2 .
mFails . ,
.

395

50

{ P_59_2

( 3) }

const CSize = 4; { }
{ }
type

TTeam = record
mAces : integer;

{ }

mName : string;

{ }

mWins : integer;

{ }

mFails: integer;

{ }

end;
TChamp = array [1..CSize] of TTeam;
var

Champ : TChamp;

{ }

{ }

{ "" ! }
procedure BubbleSort(var arg: TChamp);
. . .
end;
var i: integer;
begin

{--- ---}

{ , }
for i:=1 to CSize do begin
Write(' : '); Readln(Champ[i].mName);
Write(' :

'); Readln(Champ[i].mAces);

Write(': ');

Readln(Champ[i].mWins);

end;
{ }
BubbleSort(Champ);
{ }
Writeln(' :');
Writeln('

');

for i:=1 to CSize do begin


Write(i:3,' ':3, Champ[i].mName,
Champ[i].mAces:(20-Length(Champ[i].mName) ));
Writeln(Champ[i].mWins:8);
end;
Readln;
end.

.
, ? !
, .
396

50

,
.
RECORD...END,
, .
,
.
,
.

?
) P_50_2 , .
) .
, , ?
)
. ,
.

397

51

, .
. , ,
! .


, .
, .
, .
. 0, 1 .
, ,
, .
, ,
. , ?
, ,
.
.
, . ,
,
. .
,
, . 113.
.
, ,
, .
.
, . ?
, .
, .
,
, . :
, ,
.
.

398

51

()


()

. 113


. 113,
.
(Section ). ,
, .
,
. ,
, :
( ) ,
;
;
, , , ,
;
,
.
. .
var

B : Boolean;

C : char;

I : integer;

S : string;


,
N , . 114.

399

51

, N

N+1

N+2

N+3

N+4

N+4+255

. 114


.
, 256 .
;
. N
( ),
.

,
, .
, !
(-
POINTER). , .
, , ,
.
var

P : ^integer;

{ }

N : integer

{ }

P:= @N

{ N }

P^:= 125;

{ }

Writeln(N);

{ 125 }

begin

end.

- P.
^, ,
. P
INTEGER.

400

51

P:= @N

P N. P
, N.
N .
.
P:= Addr(N)


P^:= 125;

N 125. ? N
! ^, P.
. ,
125 , P,
N.
, .
, ,
. , .
Writeln(100+P^);

{ 225 }

Writeln(100+N);

{ 225 }


? !
, .
var

PI : ^integer;

{ }

PC : ^Char;

{ }

PS : ^String;

{ }

TYPE,
-.

401

51

type

PInt = ^Integer;

{ }

PChar = ^Char;

{ }

PString = ^String;

{ }

, .
, -
P ( Pointer ).
, , .
var

p1, p2 : PInt;

{ }

p3

{ }

: PChar;

,
, , ? ,
. , ,
.
,
, .
P1 := @X1;

{ P1 X1 }

P2 := P1;

{ X1 }

X1 (
X1 ).
, ?
, , ,
.
NIL. ,
. NIL , .
p1 := nil;

{ p1 }

p3 := nil;

{ p3 }

, ,
(. 115).

402

51

NIL
( )
1

. 115

. 115, , .
, , NIL.


, . ,
.
. : ,
. .
if p1=p2 then ...
if p1<>p2 then ...
if p3=nil then ...

NIL , . NIL ,
!
NIL,
Assigned. ,
. .
p1 := @X;

p3 := nil;

Writeln (Assigned(p1));

{ true }

Writeln (Assigned(p3));

{ false }

Assigned FALSE, NIL.

403

51


,
. ,
. ^, .
.
p1 := @X;

{ P1 }

X := 25;
Writeln (p1^);

{ 25 }

X := 100;
Writeln (p1^);

{ 100 }

, X P1^.
, P1=@X, P1^=X ( ?).
, ,
. ? . ,
, .


, .
,
. Pointer,
, NIL.
var

P1, P2 : pointer;

N : integer;

S : string;

begin
P1:= @N;

P2:= @S;

if P1=P2 then Writeln(' ');


if P1<>nil then Writeln(' ');
end.


, ,
.

404

51

{ P_51_1 }
var A, B, C : integer;
p1, p2, p3 :^integer;

{ }
{ }

begin
{ }
A:= 10; B:= 20; C:= 30;
{ }
p1:= @A;

Writeln(p1^);

p1:= @B;

Writeln(p1^);

p1:= @C;

Writeln(p1^);

{ }
p1:=@B; p2:=p1; p3:=p1;
Writeln(p1^:6, p2^:6, p3^:6);
{ }
C:= 2 * p1^;
Writeln(C);

{ C= 2 * B = 40 }

Readln;
end.

.
10
20
30
20

20

20

40

, ,
. , : , ,
.
P_51_2 ,
, ?

405

51

{ P_51_2 , }
type

PBool= ^boolean;

{ }

PInt = ^integer;

{ }

PStr = ^string;

{ }

var B : boolean;
I : integer;
S : string;
pB : PBool;

{ }

pI : PInt;

{ }

pS : PStr;

{ }

begin
{ }
pB := @B; pI := @I; pS := @S;
{ }
pB^ := true;
pI^ := 10;
pS^ := 'Hello!';
{ }
Writeln(B:6, I:6, S:10);
{ }
Writeln('Boolean = ',SizeOf(Boolean):6, SizeOf(PBool):6);
Writeln('Integer = ',SizeOf(integer):6, SizeOf(PInt ):6);
Writeln('String

= ',SizeOf(String ):6, SizeOf(PStr ):6);

Readln;
end.

.
true

10

Hello!

Boolean = 1

Integer = 2

String

= 256

. ,
4 ( ,
, ).
.
.

406

51

,
.
,
,
@ Addr.
.
.

, NIL.

: ,
.
,
; .
,
32- 4 .

?
) ? .
var

P1 : ^Integer;

P2 : ^String;

N : Integer;

S : String;

begin
P1 := @S;
P2 := @N;
end.

) ? ?
var

P1 : ^Integer;

begin
P1 := 0;
P1^ := 30;
P1 := nil;

Writeln(P1^);

end.

) P_51_1 P1
P1^ ( Ctrl+F7).
, . P_51_2.

407

52


; ,
. ...
?



. .
, .
,
. ,
, .
.
. , ,
, ? ,
? , ,
! !
,
. , .
. -,
, ?
: - ,
.
,
. , ,
. ! !

!
51- ,
. , ,
. (- Heap).
.
.
? , ! ,
.
, . ,
! ,
.
408

52

,
. ,
New Dispose .


, New (
).
.
, .
. .
var

York : ^Integer;

{ }

New(York);

{ }

begin
York^:=123;
Writeln(York^);

{ 123 }

end.

York.
New(York) 2 (
). York.
,
.
,
( 2 )? ,
.


,
( ).
, , , .
Dispose
. , ,
.
.

409

52

var

ps : ^string;

{ }

New(ps);

{ 256 }

begin
ps^:=Hello !;
Writeln(ps^);

{ Hello ! }

Dispose(ps);

{ 256 }

end.

256 ,
. .
, , .
, .
New,
.
, Dispose,
.
.
.
. (
, ) ,
.
.

,
,
, . .

var

ps : ^string;

begin
ps^:=Hello !; { }
end.

, ,

.

410

52


var

ps : ^string;

begin
ps := nil;
ps^:=Hello !; { }
end.

:
.

var

ps : ^string;

begin
New(ps);

ps^:=Hello !;

{ }

Dispose(ps);
ps^:=Bye !;

{ , ! }

end.

,
. .
var

p1, p2 : ^string;

begin
New(p1);
p2 := p1;

{ }

Dispose(p2);

{ p2 }

p1^:=Hello !; { , ! }
Dispose(p1);

{ ! }

end.

. ,
.
.
! , !

. ,
,
. ,
. , .

411

52

var

p1, p2 : ^string;

begin
New(p1);
p2 := p1;

New(p2);

{ }

{ }

Dispose(p1); { ... }
Dispose(p2); { ... ! }
end.

, p2
. , !
,
.
,
.
!

.

, ,
.

, .
New,
.
,
.
,
Dispose.
;
,
.

?
) ,
.
.

412

52

type

pb = ^byte; pw = ^word; pe = ^extended;

var

b : byte;

w : word;

e : extended;

begin
Writeln(SizeOf(b):5, SizeOf(pb):5);
Writeln(SizeOf(w):5, SizeOf(pw):5);
Writeln(SizeOf(e):5, SizeOf(pe):5);
Readln;
end.

) .
var

p1, p2 : ^integer;

begin
p1 := 10;
p2^:= 20;
New(p1);
p2:= p1;
p1^:= '!';
Dispose(p1);
Dispose(p2);
end.

413

53

.
, ,
, ,
. . 116, .

^Char

^LongInt

^String

Char
Longint
String

. 116

,
. ,
.
.



. ,
, .
, , .
.

414

53

type

TRec = record

{ }

mNum : integer;

{ 2 }

mFam : string[31];

{ 32 }

mAddr: string[63];

mTel : integer;

{ 2

64 }
}

end;

:
31 63 . ,
: 2+32+64+2 = 100 (
, ?).
( ).
type

TBase = array [1...1000] of TRec;

, 100 x 1000 = 100000 . !


, , (Borland Pascal,
). ,
.
?
.
4 x 1000 = 4000 ,
. ?
( ). ,
,
. . 117 .
PRec

PRec

TRec

TRec
TRec

. 117
415

53

- ?
. , ,
, - .
, ,
.
type

PRec = ^TRec;

.
type

TBase = array [1..1000] of PRec;

, .
. ,
: ,
. ,
.
, .
(
). ,
.
6723

2199

P_53_1 , .
{ P_53_1 }
const CSize = 1000;
type

{ }

TRec = record

{ }

mNumber : integer;

{ }

mFam

{ }

: string[31];

end;
PRec = ^TRec;

{ }

TBase = array[1..CSize] of PRec;


var

{ }

DataBase : TBase;

{ }

Count:

{ }

integer;

416

53

{ }
function ReadData(var F : text): integer;
var

N : integer;

{ }

S : string;

{ }

P : PRec;

{ }

i : integer;

{ }

begin
Reset(F);

i:=0;

while not Eof(F) and (i<CSize) do begin


Inc(i);

{ i+1 }

{ }
Read(F, N);

Readln(F, S);

{ }
while (S[1]=' ') do Delete(S,1,1);
New(P);

{ }

{ }
P^.mNumber := N;

P^.mFam := S;

{ }
DataBase[i]:= P;
end;
Close(F);

ReadData:= i;

end;
procedure ExpoDataBase;
var

{ }

i : integer;

begin
i:=1;
{ }
while (i<=CSize) and Assigned(DataBase[i]) do begin
{ , }
Writeln(DataBase[i]^.mNumber :6, '':4, DataBase[i]^.mFam);
Inc(i);

{ i+1 }

end;
end;
var
begin

F : text;

i : integer;

{--- ---}

for i:= 1 to CSize do DataBase[i]:= nil;


Assign(F,'P_50_1.in');
Count:= ReadData(F);
Writeln (' : ',Count);
ExpoDataBase;

Readln;

end.

417

53

.
CSize=1000.
ReadData
. Read(F,N)
. Readln(F,S)
. S
, .
ReadData
P.
, P
.
P, .
New(DataBase[i]); { -, }
DataBase[i]^.mNumber := N;

{ }

DataBase[i]^.mFam := S;

{ }


, .
ExpoDataBase ,
. Assigned(DataBase[i])
WHILE DataBase[i]<>NIL ,
.
.
,
NIL .
, NIL.
for i:= 1 to CSize do DataBase[i]:= nil;

.
FillChar(DataBase, SizeOf(DataBase), 0);

, ?
FillChar,
.
NIL.
, ,
P_53_1.
418

53


,
. ,
, . P_53_2,
,
P_53_1.
{ P_53_2 }
const CSize = 1000;
type

{ }

TRec = record

{ }

mNumber : integer;

{ }

mFam

{ }

: string[31];

end;
PRec = ^TRec;

{ }

TBase = array[1..CSize] of PRec;


var

{ }

DataBase : TBase;

{ }

Count:

{ }

integer;

{ }
function ReadData(var F : text): integer;
{ P_53_1 }
end;
{ }
procedure ExpoDataBase;
{ P_53_1 }
end;
{ SelectionSort }
procedure SelectionSort(var arg: TBase; Right : integer);
var

L, R : Integer;

T : PRec;

begin
for L := 1 to Right-1 do
{ }
for R := Right downto L+1 do begin
{ ,
}
if arg[L]^.mNumber > arg[R]^.mNumber then begin
{ }
T:= arg[L];

arg[L]:= arg[R]; arg[R]:= T;

end;
end;
end;

419

53

var

F : text;

begin

{--- ---}

FillChar(DataBase, SizeOf(DataBase), 0);


Assign(F,'P_53_1.in');
Count:= ReadData(F);

{ }

Writeln(' : ');
ExpoDataBase;

Readln;

SelectionSort(DataBase, Count);

{ }

Writeln(' : ');
ExpoDataBase;

Readln;

end.

.
( 43).
, .
-, , . 49
( ?),
. .
, . ,
, .
.
, .
- :
, . ?
. ,
.
,
, .
, .

Right ,
.

,
.
NIL.

.

420

53

,
, , .
.

?
) TRec .
( ).

.
)
.

)
. ,
.

421

54

,
. , ? ,
, ?
? . ,
. ,
, , .
.


.
: , , ,
.
? ,
. 118.


( )

NIL

. 118

( ),
.
,
. NIL, ,
, , ,
.
. ,
( ).
, - List.
422

54

, ,
. ,
. ,
. , ,
, ,
.


.
: .
type

PRec = ^TRec;

{ }

TRec = record

{ }

mNumber : integer;

{ }

mFam

: string[31];

{ }

mNext

: PRec;

{ }

end;

TRec , mNumber mFam,


mNext (Next
).
, ,
! ,
. mNext.
, PRec TRec,
.
TRec, , ! ,
, ?
, ,
, .
. ,
.


. :

, .
P_54_1, .

423

54

{ P_54_1 }
type

PRec = ^TRec;

{ }

TRec = record

{ }

mNumber : integer;

{ }

mFam

: string[31];

{ }

mNext

: PRec;

{ }

end;
var

List : PRec;

{ () }

{ }
procedure AddToList(aNumber: integer; const aFam : string);
var P : PRec;
begin
New(P); { - }
{ }
P^.mNumber:= aNumber; P^.mFam:= aFam;
P^.mNext:= List; { }
List:= P;

{ }

end;
{ }
procedure PrintList;
var P : PRec;
begin
P:= List;
while Assigned(P) do begin
Writeln(P^.mNumber, '':3, P^.mFam);
P:= P^.mNext;
end;
end;
begin

{ }

List:= nil;
AddToList(10, '');
AddToList(20, '');
AddToList(30, '');
PrintList;
Readln;
end.


; .
424

54

AddToList :
P^ .
, P ,
. , ,
, .
P^ List
mNext , P
. .
P^.mNext:= List;

{ }

List:= P;

{ }

, , !
,
. P ,
.
.
. 119 . 120 ;
, , List
NIL, .

P^.mNext:= List;

NIL P^.mNext (
).
List

P
_1

NIL

1
_1
???

. 119

425

54


List:= P;

List.
, ,
(. 120). P ,
,
List.
List

_1

_1

_1
NIL

. 120


.
List mNext .
.
. ,
.

List

2
_2

_1

1
_2
_1

???

NIL

. 121

426

54

List

_2

_2

_1

_2

NIL

_1

. 122


PrintList. ,
? , , !
While.
.
P:= List;
while Assigned(P) do begin
{ }
P:= P^.mNext;

{ }

end;

P . ,
, mNext . ,
Assigned(P) P<>NIL. ,
,
mNext NIL. ( NIL),
.
P_54_1 .
30
20
10

,
. ,
.

427

54


,
.
. ,
P_54_2.
.
{ P_54_2 }
type

PRec = ^TRec;

{ }

TRec = record

{ }

mNumber : integer;

{ }

mFam

: string[31];

{ }

mNext

: PRec;

{ }

end;
var

List : PRec;

{ () }

procedure AddToList(aNumber: integer; const aFam : string);


{--- P_54_1 ---}
end;
procedure PrintList;
{--- P_54_1 ---}
end;
{ }
function Find(aNumber: integer): PRec;
var p : PRec;
begin
p:= List; { }
{ ,
"" }
while Assigned(p) and (P^.mNumber <> aNumber)
Find:= p;

{ }

end;

428

do p:= p^.mNext;

54

var i, N : integer;
begin

P : PRec;

{--- ---}

List:= nil;
{ }
for i:=1 to 20 do AddToList(100+Random(100), '');
PrintList;

{ }

repeat

{ }

Write(' = '); Readln(N);


if N>0 then begin
P:= Find(N);
if Assigned(P)
then Writeln(P^.mNumber, '':3, P^.mFam)
else Writeln (' !');
end;
until N=0
end.

Find
, .
, NIL.

.
( -!).
, .


, .
? ,
, .
? !
, !
, , , . ,
,
.
.

, , . ,
.
, .
.
429

54

. ,
.
: ,
.
, .
( . 123 . 124
). , 20, 30 40,
35. p^,
, .
q. q ( ),
(. 123).
p^.mNext:=q^.mNext;

{ }

q^.mNext:=p;

{ }

List

_20

P
_35

_30

2
35

20

???

_30
30

_40

40
NIL

. 123 35

, . 124.

430

54

List

_20

_35

_30

35

20

_40

_30
30

40

_35

NIL

. 124 35

. ,
, .
List:= p;

{ , }

, .
.
p^.mNext:=List;

{ }

List:=p;

{ - }


. q.
: q ,
, ,
q . , , .
q:= List;

{ }

while Assigned(q^.mNext) and (q^.mNext^.mNumber < aNumber)


do q:=q^.mNext;

q^.mNext^.mNumber
q .
P_54_3,
.
431

54

{ P_54_3 }
type

PRec = ^TRec;

{ }

TRec = record

{ }

mNumber : integer;

{ }

mFam

: string[31];

{ }

mNext

: PRec;

{ }

end;
var

List : PRec;

{ () }

{ }
procedure AddToSortList(aNumber: integer; const aFam : string);
var p, q : PRec;
begin
New(p); { - }
{ }
p^.mNumber:= aNumber; p^.mFam:= aFam;
p^.mNext:=nil;
{ ... }
if not Assigned(List)
then List:= p
else begin

{ , }

{ }

q:= List;

{ }

{ ,
}
while Assigned(q^.mNext) and (q^.mNext^.mNumber < aNumber)
do q:=q^.mNext;
if q^.mNumber > aNumber then begin
{ }
p^.mNext:=List;

{ }

List:=p;

{ }

end else begin


{ }
p^.mNext:=q^.mNext;

{ }

q^.mNext:=p;

{ }

end
end
end;

432

54

{ }
procedure PrintList;
{--- P_54_1 ---}
end;
var i: integer;
begin

{--- ---}

List:= nil; { }
{ }
for i:=1 to 20 do AddToSortList(100+Random(100), '');
{ }
PrintList;
Readln;
end.

, .



. ,
( ).
.
, : ,
, NIL.
P_54_4.
{ P_54_4 }
type

PRec = ^TRec;

{ }

TRec = record

{ }

mNumber : integer;

{ }

mFam

: string[31];

{ }

mNext

: PRec;

{ }

end;
var

List : PRec;

{ () }

{ }
procedure AddToSortList(aNumber: integer; const aFam : string);
{--- P_54_1 ---}
end;

433

54

{ }
procedure PrintList;
{--- P_54_1 ---}
end;
{ }
function Find(aNumber: integer): PRec;
var p : PRec;
begin
p:= List;

{ }

{ ,
}
while Assigned(p) and Assigned(p^.mNext) and (p^.mNext^.mNumber <= aNumber)
do p:=p^.mNext;
{ ... }
if Assigned(p) and (p^.mNumber = aNumber)
then Find:= p

{ ! }

else Find:= nil;

{ }

i, N : integer;

P : PRec;

end;
var
begin

{--- ---}

List:= nil;
for i:=1 to 20 do AddToSortList(100+Random(100), 'Family');
PrintList;

{ }

repeat

{ }

Write(' = '); Readln(N);


if N>0 then begin
P:= Find(N);
if Assigned(P)
then Writeln(P^.mNumber, '':3, P^.mFam)
else Writeln (' !');
end;
until N=0
end.

,

,
, .
434

54

,
.

.

.
.
.

?
) ;
, .
) - .
) . ?
) . :

( ).

435

55
, ,
,
.


,
.
,
. ?
, ,
150 , 10000 .
150 / 10000 = 0,015 1,5%.
,
, , .
, !
,

.


, .
, .
, :
.
, ? !
, ,
- . ,
. ,
, .
, , .
Begin, NIL, P1, q2, Words_Count, _1_
,
, .


,
. ,

436

55
, ,

, .
, .
TRec = record
mWord

{ }

: string;

{ 256 }

mCount : Longint;

{ 4 }

mNext

{ 4 }

: PRec;

end;

? :
256+4+4=264 , ! ,
. , , ,
, .
, ,
. , . ,

. 40 ,
.
TRec = record
mWord

{ }

: string[31];

{ 32 }

mCount : Longint;

{ 4 }

mNext

{ 4 }

: PRec;

end;

, 40 8, , 31-
.

,
. ? ,
mCount, ,
mCount, .
.
. .
1. .
2. ,
; ,
.
3. .
4. .

437

55
, ,

5. , ,
, .
6. 2.
. ,
, ,
. , ,
P_55_1.

.
, .
{ P_55_1 }
type

PRec = ^TRec;

{ }

TRec = record

{ }

mWord

: string[31];

{ }

mCount : Longint;

{ }

mNext

{ }

: PRec;

end;
var

List : PRec;

{ () }

{ }
function Find(const aWord: string): PRec;
var p: PRec;
begin
p:= List;

{ }

{ ,
}
while Assigned(p) and Assigned(p^.mNext) and (p^.mNext^.mWord <= aWord)
do p:=p^.mNext;
{ ... }
if Assigned(p) and (p^.mWord = aWord)
then Find:= p

{ ... ! }

else Find:= nil; { ... }


end;

438

55
, ,
{ }
procedure AddToSortList(const aWord : string);
var p, q : PRec;
begin
New(p); { - }
{ }
p^.mCount:= 1; p^.mWord:= aWord; p^.mNext:=nil;
{ ... }
if not Assigned(List)
then List:= p

{ ... }

else begin
q:= List;

{ }

{ ,
}
while Assigned(q^.mNext) and (q^.mNext^.mWord < aWord)
do q:=q^.mNext;
if q^.mWord > aWord then begin
{ }
p^.mNext:=List;

{ }

List:=p;

{ - }

end else begin


{ }
p^.mNext:=q^.mNext;

{ }

q^.mNext:=p;

{ }

end
end
end;
{ }
procedure AddWord(const aWord : string);
var P : PRec;
begin
P:= Find(aWord);
if Assigned(p)
then Inc(P^.mCount)
else AddToSortList(aWord);
end;
{ }
procedure AddLine(S: string);
const CLetter = ['A'..'Z','_'];
CDigits = ['0'..'9'];
var W : string;

i : integer;

439

55
, ,
begin
{ }
for i:=1 to Length(S) do S[i]:= UpCase(S[i]);
while Length(S)>0 do begin
{ }
while (Length(S)>0) and not (S[1] in CLetter) do Delete(S,1,1);
if Length(S)>0 then begin
W:='';
{ W }
while (Length(S)>0) and (S[1] in CLetter+CDigits) do begin
W:= W+S[1];
Delete(S,1,1);
end;
if Length(W)>1 then AddWord(W); { , }
end;
end;
end;
{ }
procedure PrintList(var F: text);
var P : PRec;
begin
Rewrite(F);

P:= List;

while Assigned(P) do begin


Writeln(F, P^.mWord, '':(20-Length(P^.mWord)), P^.mCount:5 );
P:= P^.mNext;
end;
Close(F);
end;
var S: string;
begin

F: text;

{--- ---}

List:= nil;
Assign(F, 'P_55_1.pas');
Reset(F);
while not Eof(F) do begin
Readln(F, S);
AddLine(S);
end;
Close(F);

Assign(F, 'P_52_1.OUT');

PrintList(F);

{ }

end.

440

55
, ,

, ,
. .
( ).
ADDLINE

ADDTOSORTLIST

ADDWORD

AND

APPTYPE

ASSIGN

ASSIGNED

AWORD

10

BEGIN

14

CLETTER

?
) :
;
.
.
) ,

.
) ,
: , ,
: end, deen, , 121, 221. 121 221
, end deen.

( )
, :
1 2 2
d e n 2

: ,
.
441

56
,

. -,
. ,
, . ,
- .
.

?
, 1- ,
. ,
, .
end.
Close(F);
while Pop(S) do Writeln(F, S);
{ , }
Assign(F, 'P_56_1.out'); Rewrite(F);
{ }
Close(F);
end;

.
1- ,
. ,
: , .
, ,
. ? , ?
! , .
. .
,
(
LIFO).
. ,
( 45).
.

. , .
?
442

56
,

:
, . , ,
,
(. 125).

_3

_3
_2

Stack

_2

_1

_1

NIL

. 125


. ?
.
.
, , ,
, .
type

PRec = ^TRec;

{ }

TRec = record

{ }

mStr

: string;

mNext : PRec;

{ }
{ }

end;

, , , :
PUSH, POP.
.
procedure Push(const arg : string);

, .
. ,
: , -.
.

443

56
,
function Pop(var arg : string): boolean;

arg, . ,
FALSE, ,
.
P_56_1.
{ P_56_1 }
type

PRec = ^TRec;

{ }

TRec = record

{ }

mStr

: string;

mNext : PRec;

{ }
{ }

end;
var Stack : PRec;

{ () }

{ }
procedure Push(const arg : string);
var p : PRec;
begin
New(p);

{ - }

p^.mStr:= arg;

{ }

{ }
p^.mNext:= Stack;

{ }

Stack:=p;

{ }

end;
{ }
function Pop(var arg : string): boolean;
var p : PRec;
begin
Pop:= Assigned(Stack);

{ , TRUE }

if Assigned(Stack) then begin { ... }


arg:= Stack^.mStr;

{ }

p:= Stack;

{ }

Stack:= Stack^.mNext;

{ }

Dispose(p);

{ }

end
end;

444

56
,
var F : text;
begin

S : string;

{--- ---}

Stack:= nil;

{ }

{ }
Assign(F, 'P_56_1.pas'); Reset(F);
{ , }
while not Eof(F) do begin
Readln(F, S);

Push(S);

end;
Close(F);
{ }
Assign(F, 'P_56_1.out'); Rewrite(F);
{ , }
while Pop(S) do Writeln(F, S);
Close(F);
end.

Push .
Pop, .

Dispose(p), .
,
.
,
. ,
, ! , !

!
45- .
, .
. ,
, ,
. ,
. ?
(. 126).

445

56
,

Queue

_3

_2

_3

_1

_2

_1
NIL

. 126

, . .
.
, . , ,
: ,
.

.
. NIL,
(. 127).
.
Queue

P2


P1

_3

_3
_2

_2

_1
NIL

NIL

. 127

446

56
,

, , ,
: .
PutInQue .
procedure PutInQue(var Que: PRec; const arg: string);

( )
.
, ,
GetFromQue, .
function GetFromQue(var Que: PRec; var arg: string): boolean;

: ,
FALSE, .
arg .
: ,
.
P_56_2.IN. ,
( ).
.

P_56_2.

447

56
,
{ P_56_2
type

, 2 }

PRec = ^TRec;

{ }

TRec = record

{ }

mStr

: string[31]; { () }

mNext : PRec;

{ }

end;
{ }
procedure PutInQue(var Que: PRec; const arg: string);
var p: PRec;
begin
New(p);

{ - }

p^.mStr:= arg;

{ }

{ }
p^.mNext:= Que;

{ }

Que:=p;

{ }

end;
{ ( ) }
function GetFromQue(var Que: PRec; var arg: string): boolean;
var p1, p2: PRec;
begin
GetFromQue:= Assigned(Que);
if Assigned(Que) then begin
{ }
p1:= Que;

p2:=p1;

{ , ! }
while Assigned(p1^.mNext) do begin
p2:=p1;

{ }

p1:=p1^.mNext;

{ }

end;
{ p1 ,

p2

( - , ) }
arg:= p1^.mStr;

{ }

if p1=p2

{ ... }

then Que:= nil

{ }

else p2^.mNext:= nil;

{ "" }

Dispose(p1);

{ }

end;
end;

448

56
,
var
Boys

: PRec;

{ }

Girls

: PRec;

{ }

S1, S2 : String;

{ }

Boy: boolean;

{ }

F_In, F_Out : Text;


begin

{ }

{--- ---}

{ }
Boys

:= nil ;

Girls := nil;

{ }
{ }

Assign(F_In, 'P_56_2.in');

Reset(F_In);

Assign(F_Out,'P_56_2.out'); Rewrite(F_Out);
{ }
while not Eof(F_In) do begin
Readln(F_In, S1);

{ }

Boy:= S1[1]<>' ';

{ ! }

while S1[1]=' ' do Delete(S1,1,1);


if Boy
then begin { ...}
if GetFromQue(Girls, S2)

{ }

then Writeln(F_Out,S1+' + '+S2) { -> }


else PutInQue(Boys, S1);

{ }

end
else begin { ...}
if GetFromQue(Boys, S2)

{ }

then Writeln(F_Out,S2+' + '+S1) { -> }


else PutInQue(Girls, S1);

{ }

end
end;
Close(F_In);

Close(F_Out);

end.

449

56
,
+
+
+

, 8 ,
?


, .
, ,
,
.
,
Dispose.

?
) Free Pascal MemAvail (
Memory , Available ).
.
Push Pop .
Writeln(Push :, MemAvail);

Writeln(Pop :, MemAvail);

, , .
) 45 ,
. ,
. ?

450

57

? 49-
, .

.
. .
. 128 , , .
, , .

H
B
C

I
A

D
F
E

. 128

, 38- ,
.

451

57

A B D F I
B A C I H
C B D
D A C E
E D F
F A E G
G H I F
H G I B
I A B G H

.
, ,
. ,
, ? ,
.
, - . ,
.
(. 129).

H
B
I

C
A
F
D
E
. 129

, .
, , ?.
. -, ! ?
- , !. ,
, ?
452

57


, .
.
.
(Node), (Link).
(. 130),
. ,
. . ,
,
.

. 130

: ,
, . .
, , ,
.
, .
.

453

57


. ,
. ,

. ,
, .
?

. 131

, ?
, .
,
. -
. .
, . ,
, . ?
, . ,
.
. , .
? (. 129).
.
!
.
. , -
.
. , mNext
.
, . 132.

454

57

H
mLink

mNode

mNode

mNode

mNext

mNext

mNext

NIL


G
mLink
mNext

I
mLink
mNext

B
mLink
mNext

. 132 H

(
, ). ,
, mNext,
. .

455

57

,
. mLink.
, H. ,
, mNext (
, mNext
). mNode,
. ,
, , .
. 133 , . 132.

H
B
I

. 133 , . 132

, H,
. , G
H, .
(. 134).

. 134 () ()

, ,
.
.
: ) , )
) .
456

57


() .

, , ( !).
.
type

PNode = ^TNode;

{ - }

PLink = ^TLink;

{ }

TLink = record

{ }

mLink : PNode;

{ }

mNext : PLink;

{ }

end;
TNode = record

{ () }

mName : Char;

{ ( ) }

mLinks: PLink;

{ () }

mNext : PNode;

{ }

end;
var List : PNode;

{ ( ) }

: (TNode)
(TLink).
.
List . !
, .


. .
. ,
, .
, .
A B D F I
B A C I H
C B D

, .
, , C
B D.

457

57

.
, .
, , ?
,
( ). ,
( P).
.
. , q,
, P q.
P q. ,
, , , .
,
B C, B C.
- (. 135).
, , :
;
;
.
.
function GetPtr(aName : char): PNode;

.
, , NIL.
MakeNode ,
.
function MakeNode(aName : Char): PNode;

, , Link
.
procedure Link(p1, p2 : PNode);

, .

458

57

P ?

q ?

q
P q

. 135

, .
procedure ExpoData(var F: Text);


, .
P_57_1.

459

57

{ P_57_1 }
type

PNode = ^TNode;

{ - }

PLink = ^TLink;

{ }

TLink = record

{ }

mLink : PNode;

{ }

mNext : PLink;

{ }

end;
TNode = record

{ ( ) }

mName : Char;

{ ( ) }

mLinks: PLink;

{ ( ) }

mNext : PNode;

{ }

end;
var List : PNode;

{ ( ) }

{ ( ) }
function GetPtr(aName : char): PNode;
var p : PNode;
begin
p:= List; { }
{ }
while Assigned(p) do begin
if p^.mName= aName
then break

{ ! }

else p:= p^.mNext;

{ }

end;
GetPtr:= p;
end;
{ (), List
}
function MakeNode(aName : Char): PNode;
var

p : PNode;

begin
New(p);

{ }

p^.mName:= aName;

{ }

p^.mLinks:=nil;

{ }

p^.mNext:= List;

{ }

List:= p;

{ }

MakeNode:= p;

{ }

end;

460

57

{ p1 p2 }
procedure Link(p1, p2 : PNode);
var

p : PLink;

begin
New(p);

{ - }

p^.mLink:= p2;

{ mLink p2 }

p^.mNext:= p1^.mLinks;

{ }

p1^.mLinks:= p;

{ }

end;
{ }
procedure ReadData(var F: Text);
var C : Char;
p, q : PNode;
begin
Reset(F);
while not Eof(F) do begin
if not Eoln(F) then begin

{ }

Read(F, C);

{ }

C:=UpCase(C);

{ }

p:= GetPtr(C);

{ ? }

if not Assigned(p)
then p:= MakeNode(C);
while not Eoln(F) do begin

{ , }
{ - }

Read(F, C);
C:= UpCase(C);
if C in ['A'..'Z'] then begin

{ , }

q:= GetPtr(C);

{ }

if not Assigned(q)

{ , }

then q:= MakeNode(C);


Link(p, q);

{ p q }

end
end
end;
Readln(F);

{ }

end;
end;

461

57

{ }
procedure ExpoData(var F: Text);
var p : PNode;
q : PLink;
begin
Rewrite(F);
p:= List;

{ () }

while Assigned(p) do begin


Write (F, p^.mName);

{ }

q:= p^.mLinks;

{ }

while Assigned(q) do begin


Write(F, ' ', q^.mLink^.mName); { }
q:= q^.mNext;

{ }

end;
Writeln(F);

{ }

p:= p^.mNext;

{ }

end;
Close(F);
end;
var

F_In, F_Out : Text;

{ }

begin {--- ---}


List:= nil;
Assign(F_In, 'P_57_1.in');
ReadData(F_In);

{ }

Assign(F_Out,'P_57_1.out');
ExpoData(F_Out);

{ }

end.

.
G I H F
E F D
H I G B
C D B
I H G B A
F G E A
D E C A
B H I C A
A I F D B

, , ? ,
.
462

57

. , !
, ,
.
,
. !

, .

.
.
,
.

?
) (. 128)
. ,
. ,
.
)
. .
)
. ?
.
) , .
, .

, -
. .
?

463

58
!
, ,
. , ,
E H, .
, F G (. 136). ,
, ,
.

H
B
I

C
A
F
D
E

E H
E H

. 136 E H

? !
- .
, 49- , ?
. .


, ?
! , ,
? ,
464

58
!

. ,
, . ,
.
. 137 (
). .
() : 1) , 2) ,
3) , .
, ,
.
? E.
. ,
E
.

H
B
I

C
A
F
D
E

. 137 E

:
?
, . , E
, D F,
. 138. , ,
.

465

58
!

H
B
I

C
A
F
D
E

: D, F

. 138

, , .
,
.
, E , D F
( D, F
). . ,
D A C.
-
. ( D F)
, . 139 . 140.
.

466

58
!

H
B
I

C
A
F
D
E

: F, A, C

. 139 D

H
B
I

C
A
F
D
E

: A, C, G

. 140 F

467

58
!

, . ? ,
,
. ,
, ,
.
, , , ?.
, !
, E,
,
(. 141).

H
B
I

C
A
F
D
E

. 141

,
. ,
. , D F
E, . G
F, H G.
.
, .
,
. ,
, ,
( , ).
, .
? ,
468

58
!

, .
mPrev . , F D
E.

, .
,
49- . ,
, ?
.
,
, .
, ,
. 142.

H
B
I

C
A

3
2

F
D

. 142

.
, ,
, .
,
. . ,
,
.


, ? -,
mPrev
469

58
!

. -, ,
mDist .
: , . mColor ,
: White, Gray, Black.
.
type

TColor = (White, Gray, Black); { : , , }


TNode = record

{ ( ) }

mName : Char;

{ ( ) }

mColor: TColor;

{ , }

mDist : integer;

{ , -1 }

mPrev : PNode;

{ , }

mLinks: PLink;

{ () }

mNext : PNode;

{ }

end;

!
.
, .
,
.
.
P_58_1 P_57_1,
, .
, .
procedure PutInQue(arg: PNode);
function GetFromQue(var arg: Pnode): boolean;

, ,
P_56_2.
, .
,
InitList. -
Expand, .
procedure Expand(arg : PNode);

, arg .
, .

470

58
!

:
mDist , ,
. , ,
.
WHILE, ,
. GetFromQue (
, ),
, ,
. P
WHILE.
( ), GetFromQue
, WHILE .
. ,
, , WHILE .
, .
, ( ).
{ P_58_1 }
type

PNode = ^TNode;

{ - }

PLink = ^TLink;

{ }

TColor = (White, Gray, Black);


TLink = record

{ }

{ }

mLink : PNode;

{ }

mNext : PLink;

{ }

end;
TNode = record

{ ( ) }

mName : Char;

{ ( ) }

mColor: TColor;

{ , }

mDist : integer;

{ , -1 }

mPrev : PNode;

{ , }

mLinks: PLink;

{ ( ) }

mNext : PNode;

{ }

end;

471

58
!
var List : PNode;
Que

: PLink;

{ }
{ }

{ ( ) }
function GetPtr(aName : char): PNode;
{ P_57_1 }
end;
{ () }
function MakeNode(aName : Char): PNode;
{ P_57_1 }
end;
{ p1 p2 }
procedure Link(p1, p2 : PNode);
{ P_57_1 }
end;
{ .}
procedure ReadData(var F: Text);
{ P_57_1 }
end;
{

Que }

procedure PutInQue(arg: PNode);


var p: PLink;
begin
New(p);

{ - }

p^.mLink:= arg;

{ }

{ }
p^.mNext:= Que;

{ }

Que:=p;

{ }

end;

472

58
!
{ }
function GetFromQue(var arg: Pnode): boolean;
var p, q: PLink;
begin
GetFromQue:= Assigned(Que);
if Assigned(Que) then begin
{ () }
p:= Que;

q:=p;

{ , ! }
while Assigned(p^.mNext) do begin
q:=p;

{ }

p:=p^.mNext;

{ }

end;
{ p q }
arg:= p^.mLink;
if p=q

{ ... }

then Que:= nil

{ }

else q^.mNext:= nil;

{ "" }

Dispose(p);

{ }

end;
end;
{ () "", arg }
procedure Expand(arg : PNode);
var p : PNode;
q : PLink;
begin
arg^.mDist:= 0;

{ = 0 }

arg^.mColor:= Gray;

{ }

PutInQue(arg);

{ }

while GetFromQue(p) do begin

{ }

Write(p^.mName, ' ->');

{ }

q:= p^.mLinks;

{ }

while Assigned(q) do begin


if q^.mLink^.mColor = White then begin

{ }

q^.mLink^.mColor:= Gray;

{ }

q^.mLink^.mDist:= p^.mDist +1;

{ }

q^.mLink^.mPrev:= p;

{ , }

PutInQue(q^.mLink);

{ }

Write(q^.mLink^.mName:2);

{ }

end;

473

58
!
q:= q^.mNext;

{ }

end;
p^.mColor:= Black; { }
Writeln;

{ }

end;
end;
{ " " }
procedure InitList;
var p : PNode;
begin
p:= List; { }
{ }
while Assigned(p) do begin
p^.mColor:= White;

{ }

p^.mDist := -1;

{ -1 }

p^.mPrev := nil;

{ , }

p:= p^.mNext;

{ }

end;
end;
var

F_In {, F_Out} : Text;

begin

{ }

C : Char;

{ }

Start : PNode;

{ , "" }

{--- ---}

{ }
List:= nil;

Que:= nil;

Assign(F_In, 'P_57_1.in');
ReadData(F_In);

{ }

{ }
repeat
Write(' = '); Readln(C);
C:= UpCase(C);
if not (C in ['A'..'Z']) then break;
Start:= GetPtr(C);

{ }

if Assigned(Start) then begin { , }


InitList;

{ }

Expand(Start);

{ "" Start }

end;
until false
end.

474

58
!

,
, .
, . ,
E .
E -> F D
F -> G A
D -> C
G -> I H
A -> B
C ->
I ->
H ->
B ->

Expand,
. E
F D. F G A,
. , C, I, H B
, .
(. 143).

H
3

B
G

C
A

F
D
E
0
. 143

475

58
!

,
(. 142), . ?
?
, ,
. ,
.
. , .
, .
. ,
, .


.
, :
.
.
,
.
, , , .
NIL,
. MakePath ,
.
function MakePath(arg : PNode): string;

, ,
. A B C.
.
, : .
,
, MakePath.
, ,
.
, :
;
;
;
;
.
476

58
!

, , ,
. ,
. , ,
P_58_2.
P_57_1 P_58_1, .
{ P_58_2
type

{ P_58_1 }

var List : PNode;


Que

: PLink;

{ }
{ }

{ ( ) }
function GetPtr(aName : char): PNode;
{ P_57_1 }
end;
{ () }
function MakeNode(aName : Char): PNode;
{ P_57_1 }
end;
{ p1 p2 }
procedure Link(p1, p2 : PNode);
{ P_57_1 }
end;
{ }
procedure ReadData(var F: Text);
{ P_57_1 }
end;
{

Que }

procedure PutInQue(arg: PNode);


{ P_58_1 }
end;
{ }
function GetFromQue(var arg: Pnode): boolean;
{ P_58_1 }
end;

477

58
!
{ " " }
procedure InitList;
{ P_58_1 }
end;
{ () "", arg }
procedure Expand(arg : PNode);
{ P_58_1,
}
end;
{ }
function MakePath(arg : PNode): string;
var p : PNode;
S : string;
begin
S:= arg^.mName;

{ }

p:= arg^.mPrev;

{ }

while Assigned(p) do begin

{ }

S:= p^.mName +' -> '+ S;

{ }

p:= p^.mPrev;

{ }

end;
MakePath:= S;
end;
var

F_In {, F_Out} : Text; { }

begin

C1, C2 : Char;

{ "" "" }

Start, Stop : PNode;

"" "" }

{--- ---}

{ }
List:= nil;

Que:= nil;

Assign(F_In, 'P_57_1.in');
ReadData(F_In);

{ }

{ }
repeat
Write('= '); Readln(C1);
C1:= UpCase(C1);
if not (C1 in ['A'..'Z']) then break;
Write('

= '); Readln(C2);

C2:= UpCase(C2);
if not (C2 in ['A'..'Z']) then break;

478

58
!
Start:= GetPtr(C1);

{ }

Stop:= GetPtr(C2);

{ }

if Assigned(Start) and Assigned(Stop) then begin


{ , }
InitList;

{ }

Expand(Start);

{ "" Start }

Writeln (Stop^.mDist:3, :3, MakePath(Stop));


end;
until false
end.

, .
:

E -> F -> G -> H

! !
!
? ! .
!


. ,
.

.
, .

?
) , 20 ,

P_58_2.
) , .
.
? -.
) mDist TLink.

479

58
!
TLink = record

{ }

mLink : PNode;

{ }

mDist : integer;

{ }

mNext : PLink;

{ }

end;

,
.
) ,
( ).
A C 20 E 40

, , .
. ,
A C 20 , A E 40 .
.
)
. ,
, ,
mDist.
, ,
, .
!
) , ,
, .
( ).
?

480

59

59

, ?
, ,
.


, ,
. ,
, . :
, . , , .
: , , , .
.
, . ,
. , ,
, , .
.
.

. !
, ,
. .
, .
,
. ,
, .
, ,
, !
,
.
, .
, .
, --
.
.
, ? -?
? ,
. ?

481

59

?
! , ?
? ,
, ? ?
! .
, ,
(UNIT).

, .
.
.
, , .
.
. ,
. IDE ,
, .
, -,
. ,
.


.
, .
, ,
. ,
.
? : -
? , , . ,
, .
.
. ,
P_56_1. ,
. , , ,
. , P_56_1
. ,
, .
.

482

59

{ P_56_1 }
type

PRec = ^TRec;
TRec = record
mStr

: string;

mNext : PRec;
end;
var Stack : PRec;

{ }

procedure Push(const arg : string);


{ . . . }
end;
function Pop(var arg : string): boolean;
{ . . . }
end;
{ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - }
var F : text;
begin

S : string;

{--- ---}

{ . . . }
end.

, - ,
. .
Push, Pop,
Stack , MyLibr
. .

.
, , ,
, P_59_1.
{ P_59_1 }
var F : text;
begin

S : string;

{--- ---}

{ . . . }
end.

, , (Primary).
, P_59_1 .
? , .
. ,
MyLibr. ,
USES. ,
, USES
483

59

( ).
MyLibr, ,
.
{ P_59_1 }
uses

MyLibr;

var F : text;
begin

{ }
S : string;

{--- ---}

{ . . . }
end.

, PAS USES ,
. ,
, MyLibr. ,
MyLibr.
F9. ,
.
MyLibr.
, . ,
. ,
(
).
unit MyLibr;

{ }

interface

{ }

{. . .}
implementation

{ }

{. . .}
end.

END . ,
, .
UNIT (),
. UNIT ,
. ,
PAS. , 64- ,
. , MyLibr.

:
INTERFACE
()

IMPLEMENTATION () .
.
(, !).
484

59

, .
( ), :
, , , . ,
, . ,
IMPLEMENTATION ,
.
unit MyLibr;

{ }

interface

{ }

implementation

{ }

type

PRec = ^TRec;
TRec = record
mStr

: string;

mNext : PRec;
end;
var Stack : PRec;

{ }

procedure Push(const arg : string);


{ . . . }
end;
function Pop(var arg : string): boolean;
{ . . . }
end;
end.

. INTERFACE
, . ?
, , . ,
. ,
, , .
, .
.
( )
. .
,
. ? ?
,
, .
.
,
Stack, Push Pop. , .

485

59

, ,
.
.
!
, .
, .
unit MyLibr;

{ }

interface

{ }

type

PRec = ^TRec;
TRec = record
mStr

: string;

mNext : PRec;
end;
var Stack : PRec;

{ }

procedure Push(const arg : string);

{ }

function Pop(var arg : string): boolean;

{ }

implementation

{ }

procedure Push(const arg : string);


{ . . . }
end;
function Pop(var arg : string): boolean;
{ . . . }
end;
end.

Stack ,
, .
.
.
,
.

. ,
, ,
. . 144 :
, .

486

59

. 144 P_59_1


.
Ctrl+F9,
, .
. Ctrl+F9
, : Cannot run a unit
. , ,
. ,
.
, IDE
, , P_59_1.
Compile Primary file
(. 145). , ,
. MyLibr
, -, .
?
, Compile Clear
Primary file.

487

59

. 145


, , ,
.
, Stack
.
Stack:= nil;

{ }

- ,
. ,
MyLibr, .
.
BEGIN,
END. ,
. .
unit MyLibr;
{ . . . }
begin

{ }

Stack:= nil;

{ }

end.

? ,
( P_59_1).
, .
.
, ,
USES ( ).
.
, .
488

59

,
, .
, . ,
Stack ,
.
.
.
unit MyLibr;

{ }

interface

{ --- --- }

procedure Push(const arg : string);

{ }

function Pop(var arg : string): boolean; { }


implementation
type

{ --- --- }

PRec = ^TRec;

{ }

TRec = record

{ }

mStr

: string;

mNext : PRec;

{ }
{ }

end;
var Stack : PRec;

{ }

{ }
procedure Push(const arg : string);
var p : PRec;
begin
New(p);

{ - }

p^.mStr:= arg;

{ }

{ }
p^.mNext:= Stack;

{ }

Stack:=p;

{ }

end;

489

59

{ }
function Pop(var arg : string): boolean;
var p : PRec;
begin
Pop:= Assigned(Stack);

{ , TRUE }

{ ... }
if Assigned(Stack) then begin
arg:= Stack^.mStr;

{ }

p:= Stack;

{ }

Stack:= Stack^.mNext;

{ }

Dispose(p);

{ }

end
end;
begin

{ --- --- }

Stack:= nil;

{ }

end.

Push
Pop. .
{ P_59_1 }
uses MyLibr;
var F : text;
begin

S : string;

{--- ---}

{ }
Assign(F, 'P_56_1.pas'); Reset(F);
{ , }
while not Eof(F) do begin
Readln(F, S);

Push(S);

end;
Close(F);
{ }
Assign(F, 'P_56_1.out'); Rewrite(F);
{ , }
while Pop(S) do Writeln(F, S);
Close(F);
end.

, ,
?

490

59


, ,
: .

.
, . . 146 ,
. , ,
: , , ,
. . ,
, ,
. ,
,
. , ,
, .


:
, ? ,
.
.
, ,
, .
,
.
:
, , ,
USES. , .
, , ,
.
.
, !
. ,
, - !
: , ,
.
. ?
. ,
. ,
.

491

59

MyLibr.Push(S);
while MyLibr.Pop(S) do . . .

, Push Pop
MyLibr .

unit

...
.

interface

, ,

uses

...

const
type
var

...
...
...

procedure
function

...
...

implementation
uses

...

const
type
var

...
...
...

procedure
function

...
...

,
,

.
, ,
,
.

.
,

begin

...
end.

. 146

, , USES.
SYSTEM.
, .
SYSTEM USES .
492

59

,
SYSTEM. .
, .
System.Writeln(F);

{ }

MyModule.Writeln(S);

{ }

,
USES (. 146).

. , :
, USES
, .
. , .


, IDE
.


( PAS)


( TPU)

F9, Alt+F9

F9

F9


( PAS)

EXE-

F9
(F9 Alt+F9)
(F9)


( TPU)

. 147


TPU. Turbo
493

59

Pascal Unit .
, . .

Alt+F9, Compile Compile.
,
, TPU.
(. 148).

. 148

, .
.
F9 ( Compile Make)
USES , .
,
(PAS) (TPU).
( TPU- ),
. ,
.
EXE-.


, IDE,
TPU-.
,
.
( , IDE Borland Pascal).

494

59

uses CRT;

{ CRT Sound, NoSound, Delay, ClrScr }

procedure Beep;

{ }

begin
Sound(300);

{ 300 }

Delay(500);

{ }

NoSound;

{ }

end;
begin {--- ---}
ClrScr;

{ }

Writeln(, !);
Beep;

{ }

Readln;
end.

,
. ,
CRT .
,
CRT.TPU.
\Units (
IDE). ,
Options Directories (. 149).

. 149

, Borland Pascal
C:\BP, C:\BP\UNITS.

495

59

.
,
.
,
: , , , .
:
.
.
,
.
,
.
.

?
) P_58_1 .
?
?

496

60

,
!



, INCLUDE-.
,
.
:
. $I,
. ,
, $I ,
, .
,
.
. ,
HELLO.INC, .
Writeln(!);

HELLO.PAS .
begin {--- HELLO.PAS ---}
{$I Hello}
end.

HELLO.PAS
. $I ,
INC . ,
INCLUDE- ,
, .
,
. , ,
.
,
. .
,
Options Compiler.
497

60

Ctrl+O+O,
, , .
{$A+,B-,D+,E-,F-,G+,I-,L+,N+,O-,P-,Q-,R-,S-,T+,V-,X+,Y+}
{$M 16384,0,655360}

Options.inc ( ).
, ,
{$I Options}.
{$I Options}
. . .

,
, ,
. ? Options.inc
.


, ,
, . !
, , .

, . ,
, ,
. , ,
, ?
. ,
? , .
.
,
.
, , .
.
, .
$DEFINE .
,
.
, .
.

498

60

{ $define Test }
{ $define Print }

.
, !
, .
:
!
, ,
.
{ $ifdef ABC }
{ , ABC }
{ $else }
{ , ABC }
{ $endif }

$IFDEF ,
$DEFINE . ,
, $ELSE , .
, $ELSE, .
, .
{ $ifdef ABC }
{ , ABC }
{ $endif }

, $DEFINE $IFDEF$ELSE$ENDIF
.
. , ,
,
. , ,
.
, -.

. .

499

60

{$define Debug }
const
{$ifdef Debug}
FName = '';

{ }

{$else}
FName = 'Hello.out';

{ }

{$endif}
var F : text;
begin
Assign (F, FName);

Rewrite(F);

Writeln(F, , !');
{$ifdef Debug}

Readln;

{$endif}

Close(F);
end.

Debug (),
: . ,
.
:
, $DEFINE
.
{ define Debug , ! }

, Debug ,
FName Hello.out, Readln
, .
, ,
.
, (
). , ,
Options.inc. ,
.
{$A+,B-,D+,E-,F-,G+,I-,L+,N+,O-,P-,Q-,R-,S-,T+,V-,X+,Y+}
{$M 16384,0,655360}
{$define Test $IFDEF Test }
{$define Print $IFDEF Print }

,
.

500

60

(INCLUDE) ,
$I .
,
.

.
, .

?
)
( 31), .
.

501

61

61

, ().
, ?

-
. , IDE Borland Pascal,
. ,
APP.TPU UNITS,
, .
{P_61_1 Turbo Vision }
uses App;
var A : TApplication;
begin
A.Init;
A.Run;
A.Done;
end.

? , ,
? , (. 150).

. 150 MyApp

, Borland Pascal? ,
? .
502

61

, .
Exit , Alt+X.
, , !
, .
Turbo Vision,
IDE Borland Pascal.


: , . ?
,
.
! - .
,
.
. ,
,
, ,
. !
, ,
.
; ?
: , , , . !
.
!
.
, .
.
. , ,

. , ,
( ).


, , :
;
;
.
.

503

61

.
,
. ,
.
, ,
.

, ,
RECORD OBJECT. ,
, .
type

TPerson = object
mBearing : integer;

{ }

mName

: string;

{ }

mFam

: string;

{ }

end;

TPerson (),
.
Report. !
.
type

TPerson = object
mBearing : integer;

{ }

mName

: string;

{ }

mFam

: string;

{ }

procedure Report;

{ }

end;

. , Object Pascal,
(class) .

, ,
. , , .
, , ,
. ( ),
,
, , .
Report .
504

61

procedure TPerson.Report;
begin
Writeln(mBearing:6, ': '+mFam:20, '

: '+mName);

end;

. ?
, .
, ,
.
,
, , . ?
, .
var P : TPerson;

{ - }

begin
P.mFam:=;
P.mName:= ;
end.

, -
. .
. PROCEDURE
: CONSTRUCTOR.
, Init () Create
(). ,
.
type

TPerson = object
{ . . . }
{ }
constructor Init(aBearing: integer; const aName, aFam : string);
end;
{ }

constructor TPerson.Init(aBearing: integer; const aName, aFam : string);


begin
mBearing:= aBearing;

mName:= aName;

mFam:= aFam;

end;

Init
. - P ,
.
505

61

var P : TPerson;

{ - }

begin
P.Init(1995, '', '');

, !
, .
P_61_2 , TPerson:
, , -,
.
{ P_61_2 () }
type

TPerson = object
mBearing : integer;

{ }

mName

: string;

{ }

mFam

: string;

{ }

constructor Init(aBearing: integer; const aName, aFam : string);


procedure Report;

{ }

end;
{--- ---}
constructor TPerson.Init(aBearing: integer; const aName, aFam : string);
begin
mBearing := aBearing;

mName

:= aName;

mFam

:= aFam;

end;
procedure TPerson.Report;
begin
Writeln(mBearing:6, ': '+mFam:20, '

: '+mName);

end;
var P1, P2 : TPerson;
begin

{ }

{--- ---}
P1.Init(1985, '', '');
P2.Init(1995, '', '');
P1.Report;
P2.Report;
Readln;

end.

, .
,
.
.
506

61


.
.
, .
, Turbo Vision,
, ,
, .
-,
( ,
).
-!
.
.
, .
.
.

, , ! ,
, . , , ,
, . : ,
, , ,
. , . ,
.
,
() .
: .
.
type

= object
procedure

; virtual;

procedure

; virtual;

end;

VIRTUAL,
.
, .
. , VIRTUAL
,

. , -.
507

61

,
, , .
type

= object ()
procedure

; virtual;

procedure

; virtual;

procedure

_;

procedure

_;

procedure

_;

end;

,
OBJECT.
, ,
.
, .
, .
.
, . 151.

. 151


,
. TPerson ()
: (TMilitary)
(TCivil), . 152.

. Init Report
508

61

, .
,
.

TPerson

TMilitary

TCivil

. 152 -

, ?
, .
TMilitary mRank . ,
, .
Init
aRank. TMilitary
.
constructor Init(aBearing: integer; const aName, aFam, aRank : string);

, ,
, . , .
, VIRTUAL? !
, .
Report. , ,
, , .
, TMilitary,
TPerson. ,
,
!
, TPerson TMilitary
.

509

61

TPerson = object
mBearing : integer;

{ }

mName

: string;

{ }

mFam

: string;

{ }

constructor Init(aBearing: integer; const aName, aFam : string);


procedure Report; virtual;
end;
TMilitary = object (TPerson)
mRank

: string;

{ }

constructor Init(aBearing: integer; const aName, aFam,


aRank : string);
procedure Report; virtual;
end;

. TPerson Report
. TMilitary mRank,
Report.

, ,
- TPerson
. ,
. , , 59,
.
, ,
TPerson .
INTERFACE , IMPLEMENTATION.
Report. PERSON
PERSON.PAS. , .
PPerson,
.

510

61

unit

Person; { , }

interface
type

PPerson = ^TPerson;

{ }

TPerson = object
mBearing : integer;

{ }

mName

: string;

{ }

mFam

: string;

{ }

constructor Init(aBearing: integer; const aName, aFam : string);


procedure Report; virtual;
end;
implementation
{--- ---}
constructor TPerson.Init(aBearing: integer; const aName, aFam : string);
begin
mBearing := aBearing;
mName

:= aName;

mFam

:= aFam;

end;
procedure TPerson.Report;
begin
Writeln(mBearing:6, ': '+mFam:20, '

: '+mName);

end;
end.

, Person, ,
.
USES Person

P_61_3 ,
.
TMilitary.
.

511

61

{ P_61_3 }
uses Person;
type

{ TPerson Person }

{ }
TMilitary = object (TPerson)
mRank

: string;

{ }

constructor Init(aBearing: integer; const aName, aFam,


aRank : string);
procedure Report; virtual;
end;
begin
end.


.
. , , .
, , ?
,
.
TPerson.Init(aBearing, aName, aFam);

TPerson
. .
INHERITED .
,
.
inherited Init(aBearing, aName, aFam);

.
, , , ,
. mRank ,
.

512

61

constructor TMilitary.Init(aBearing: integer; const aName, aFam,
aRank : string);
begin
inherited Init(aBearing, aName, aFam);

{ }

mRank:= aRank;
end;

Report . , ,
, .
Report,
. ,
.
procedure TMilitary.Report;
begin
inherited Report; { }
Writeln(' : '+mRank);
end;

, .
, .
TCivil, TPerson.
,
. ,
mLevel . , ,
Report.
, , .
TMilitary TCivil,
. ?
? , .


52- .
. ,
PPerson .
type

PPerson = ^TPerson;

, ,
.

513

61

var

P : PPerson;

{ }

begin
New(P);

{ }

P^.Init(1985, '', '');

{ }

,
.
, . New (
New) , .
: -
, . ,
TPerson
.
P:= New(PPerson, Init(1985, '', ''));

, - PPerson,
TPerson!

, ,
. , .
var

P1 : PPerson;

{ }

P2 : PMilitary;

{ }

P3 : PCivil;

{ }

P1 , P2 P3
. ,
,
.
P1:= P2;
P1:= P3;

, ? !
! ,
,
. , P1
: TPerson,
, Report.
Report,

514

61

,
P1. !
P1:= New(PPerson, Init(1985, '', ''));
P1^.Report;

{ TPerson.Report }

P1:= New(PCivil, Init(1995, '', '', 12));


P1^.Report;

{ TCivil.Report }

P1:= New(PMilitary, Init(1985, '', '', ''));


P1^.Report;

{ TMilitary.Report }

, ,
, , .
, .
. !,
- .

, -.
. .
type

TA = object
constructor Init;
procedure Report; virtual;
end;
TB = object
constructor Init;
procedure Report; virtual;
end;


. ,
!
P_61_3, ,
.

515

61

{ P_61_3 }
uses Person;
type

{ TPerson Person }

PMilitary = ^TMilitary;

{ }

TMilitary = object (TPerson)


mRank

: string;

{ }

constructor Init(aBearing: integer; const aName, aFam,


aRank : string);
procedure Report; virtual;
end;
PCivil = ^TCivil;

{ }

TCivil = object (TPerson)


mLevel

: integer;

{ }

constructor Init(aBearing: integer; const aName, aFam : string;


aLevel: integer);
procedure Report; virtual;
end;
{--- ---}
constructor TMilitary.Init(aBearing: integer; const aName, aFam,
aRank : string);
begin
inherited Init(aBearing, aName, aFam);
mRank:= aRank;
end;
procedure TMilitary.Report;
begin
inherited Report;
Writeln(': '+mRank);
end;

516

61

{--- ---}
constructor TCivil.Init(aBearing: integer; const aName, aFam : string;
aLevel: integer);
begin
inherited Init(aBearing, aName, aFam);
mLevel:= aLevel;
end;
procedure TCivil.Report;
begin
inherited Report;
Writeln(': ', mLevel);
end;
var Persons : array[1..3] of PPerson;

{ }

i : integer;
begin

{--- ---}

{ , }
Persons[1]:= New(PPerson, Init(1985, '', ''));
Persons[2]:= New(PCivil, Init(1995, '', '', 12));
Persons[3]:= New(PMilitary, Init(1985, '', '', ''));
{ }
for i:=1 to 3 do Persons[i]^.Report;
Readln;
end.


, ?
. ,
.
,
.
.
, : ,
, .
.
,
IMPLEMENTATION.
. ,
, - ,
517

61

.
. ?
! .
. ,
- ,
.
:
PRIVATE () PUBLIC
().
, .
type

TParent = object

{ - }

private
A, B : integer;
function Calc(arg: integer): integer;
public
Constructor Init(a, b : integer)
function GetSum: integer; virtual;
end;

A B, Calc, .
,
TParent,
, , .
type

TChild = object (TParent)

{ - }

A, B : string;
procedure Calc;
. . .
end;

A B , Calc
, . ,
!
, .
PRIVATE
PUBLIC? .
, , . ,
, .
,
. , , .
518

61

Turbo Vision.
,
.

-
.
,
, .
-

: ,
.
, ,
.

. .

.

?
)
.
TPerson

TMilitary

TCivil

,
, Report.
.

519

62
!
, ? , , ,
! .


? .
, . ?
, ? .


. , ,
, Delphi
.
, .
: , ,
.
!
? ,
. ?
, 70-
. , . ,
,
. , , .

-. , , ,
,
.

. ? .
, , ,
(
!).
.

. , ,
, .
-2 ,
(, , ). ,
, C C++
520

62
!

.
,

, . ,
Java C#.
. , WEB, : PHP, Perl, JavaScript
( !).

(Assembler ).
, , ,
. ? ,
: , .
,
! ,
, .
!
,
: . .
, .
, , , !

, .
.
- ,
. ,
. : ,
, , , . ,
, .

, ,
! , , ,
, !
,
, .
, , .
.
. ,
? ! , ,
. ! , !
521

62
!



. .
,
, .

,
.
.
(, ).
,

.
.
,
.

,
.
, .
,
.

. .
: , ,
. , ,
. , .
.
,
.

. , .
- ... !
.
,
. ,
. ,
, , .
. ,
, :
522

62
!

C ;
T ;
a ;
m .
,
.
. , ,
( , ),
- .


. ?
.
? .
,
. ,
.

, !
,
.
.
.
, ? ,
.


, , , , ,
. ,
.
: (10-
) (11- ). ,
.
.
,
. . ?
!

523

62
!


,
. ,
( 3 5 ).
. ,
. ,
.
. , ,
, .
:
.
, ,
.
.
.

. ,
, ,
. ,
.

. ,
.
, , ,
.
.
,
, .
.
( !)
, . , ,
, N, ,
( ?).
, ,
.
( ).
.

. ,
. ,
524

62
!

.
, , ,
(, ).
. .
,
, .

? .
?
, .
,
. , ABC.PAS,
ABC.IN ABC.OUT.
.
.
.
.
( ),
.
(, 5 ).
, .
,
.

.
.
,
. ,
, . .
- .
, .
. . ,
,
.
,
.
525

62
!

. .
, . ?
( ,
). ,
, . 13.
. 13

http://algolist.manual.ru

http://bestalgorithm.ru/

http://www.olympiads.ru


( )

http://neerc.ifmo.ru/school/


( )

http://www.informatics.ru

http://contest.ur.ru

http://g6prog.narod.ru


(
)

http://acm.timus.ru

http://de.ifmo.ru/cyber-net


, .
, .
, ,
.
. ,
. ,
, .

526

62
!

,
. ,
. ,
. , .
, .
, .
?
: . ?
, . ,
.
, ,
. .
,
, , .
, .
, .
( , ),
.
.
, .
.
const CTask = 'Name';
CIn = CTask+'.in';
COut = CTask+'.out';
procedure ReadData;
var F: text;
begin
Assign(F, CIn); Reset(F);
Close(F);
end;
procedure WriteData;
var F: text;
begin
Assign(F, COut); Rewrite(F);
Close(F);
end;

527

62
!
begin
ReadData;
WriteData;
end.

, CTask (
), !
.
, 1 10, .
, ,
. ,
. ( ).
, ,
.

, .
? ? ! ,
, , .
? -. -
. , .
. ,
. , . ,
? ,
. , , .
, , ...
. !

528


IDE Borland Pascal

Borland Pascal.
MS-DOS, , MS-Windows, .
:
IDE Borland Pascal ;
IDE;
CRT;
;
;
IDE;
IDE;
;
Turbo Pascal School Pak.
,
MS-Windows.
IDE, .

IDE Borland Pascal,


IDE Borland Pascal
. 90-
MS-Windows 3.1
. Borland, ,
MS-Windows. ,
Delphi. Borland
MS-DOS: , , ,
Intel 80x86. , !
MS-Windows 3.1 , MS-DOS !
, IDE,
7.1. .
, 07:00
07:01. 7.0, IDE 7.1
.

529


IDE Borland Pascal

IDE,
Pentium. CRT.

Runtime Error 200 . Borland
, .
, CRT.
.
IDE ,
.
, IDE Borland Pascal :
Borland Pascal 7.0;
Borland Pascal 7.1 (
BP7BIN.ZIP BP7ETC.ZIP):
T7TPLFIX.EXE, CRT;
.

IDE Borland Pascal


IDE , :
1.
2.
3.
4.
5.

;
IDE 7.0;
IDE 7.1;
;
.


.
.
,
D:\Distrib\Langs\Bpascal.700, .
7.0
INSTALL.EXE,
.
. Enter,
(. 153).

530


IDE Borland Pascal

. 153

,
( D). , , Enter
(. 154).

. 154 ,

. ,
. , Enter
(. 155).

531


IDE Borland Pascal

. 155 ( Borland Pascal)


, Start Installation .
,
Enter, Esc.
, .
Borland Pascal Directory ,
IDE. D:\BP,
IDE C:\Lang\BP. ,
Enter, Enter (. 155).
Lang BP .
, Program Manager Group Enter,
MS-Windows ( Dont Create).
Host Platforms Target Platforms
: ,
. ?
IDE, Borland:
80x86,
MS-Windows 3.1.
TURBO.EXE, BP.EXE BPW.EXE .
IDE BP.EXE. IDE , ?
, Host Platforms Target Platforms,
Install BP.EXE Dont Install (. 156).

532


IDE Borland Pascal

. 156 IDE

, , .
, . 157.

. 157

Start Installation Enter.


(. 158)
IDE.

533


IDE Borland Pascal

. 158 Borland Pascal

. 14.
. 14 - Borland Pascal

BGI

MS-DOS

BIN

IDE Borland Pascal,


DOC

EXAMPLES

SOURCE

Turbo Vision

UNITS

534


IDE Borland Pascal

BIN, .
BP.EXE

- IDE Borland Pascal

DPMI16BI.OVL

- IDE

RTM.EXE

- IDE

TURBO.TPL

TURBO.TPH

TVISION.TPH

- Turbo Vision

IDE Borland Pascal 7.0 ,


. IDE
7.1.
7.1

INSTALL.BAT. ,
Borland Pascal 7.0. .
install c:\Lang\BP

BP7BIN.ZIP
BP7ETC.ZIP, 7.0.
, , ,
.
install c:\Lang\Temp

Temp
IDE (. 158).
7.0.
, ,
BP7BIN.ZIP BP7ETC.ZIP
IDE. ,
7.0
7.1. ,
, 07:01.

T7TPLFIX.EXE
BIN, TURBO.TPL TPP.TPL.
, .
P, Q.
535


IDE Borland Pascal

BIN OLD
.
TURBO.TPL TPP.TPL.

. ,
, . ,
-
Turbo_rus.tph. BIN, Turbo.tph
- , Turbo_eng.tph, ,
, . BIN
Turbo.tph.
IDE . IDE
-
. IDE
, .


? ,
, . :
, .
, , :
C:\User\Pascal
,
. IDE Borland Pascal
, MS-DOS,
.
MS-DOS 8.3
( ). ,
, .
.


IDE Borland Pascal BP.EXE.
. ? .
, , IDE.
, , , .
, ,
.
BP.EXE :
536


IDE Borland Pascal

;
;
.
.
,
.
Explorer, , , .
BP.EXE , (
), ,
D:\Lang\BP\BIN. IDE
C:\User\Pascal, .
.
?
. , MS-DOS, ,
.
Alt+Enter.
, MS-Windows
. , .
, ,
. , .
. BIN
BP.EXE. ALT ,
BP.EXE , ,
! , ,
Pascal. (
F2), , Enter.
.
,
(. 159).

537


IDE Borland Pascal

. 159 MS-Windows XP

,
. ;
(
). .
, IDE,
. ,
OK.

IDE
IDE BIN ,
BP.TP BP.DSK? IDE.
.
, . ? .
, (. 160).

538


IDE Borland Pascal

. 160 IDE Borland Pascal

IDE Borland Pascal. ,


IDE, Enter OK.
IDE,
. ,
.
.
Alt+Enter.
,
(. 159).
IDE.
MS-Windows, (. 161).

. 161 MS-DOS

, IDE:
Alt+X, File Exit.
539


IDE Borland Pascal

IDE
IDE Borland Pascal ,
. ,
. , IDE
. : BP.TP,
BP.DSK BP.PSM. :
.
IDE .
, , ,
. , ?
.
- ,
( ). ,
.
.
IDE .
IDE Options Environment
Preferences (. 162). , F10.

. 162 Options Environment Preferences

Preferences ()
. 163, OK.

540


IDE Borland Pascal

. 163

, Options Save as (. 164).

. 164 Options Save as

Save Options As (. 165)


BP.TP OK. IDE
,
IDE.

541


IDE Borland Pascal

. 165

, .
, C:\User\Pascal. ,
Files .
, C:\User\Pascal\BP.TP.



MS-Windows XP . ,
MS-DOS , -
.
.
: (
!), . :
! , !
Privet! Hello!, .
, .
.

, .
1) C:\Windows\System32 (,
C:\Windows).
Autoexec.nt. .
542


IDE Borland Pascal
kb16.com ru

.
2) Windows:
Regedit
3) (. 166):
HKEY_LOCAL_MACHINE SYSTEM CurrentControlSet Control
Keyboard Layout DosKeybCodes

3
4

5
6

. 166 -

4) 00000409
.
us ru ( ).
.
! MS-DOS
, Windows.

543


IDE Borland Pascal


, .
RK.COM (
RK-866.COM), RNBOVDD.DLL.

. MS-Windows XP ,
.
C:\Windows\System32
( c:\Windows).
AUTOEXEC.NT,
.
LH %SystemRoot%\system32\rk.com /R5

, RK-866.COM,
LH %SystemRoot%\system32\rk-866.com /R5

AUTOEXEC.NT
CONFIG.NT. , .
dos=high, umb
device=%SystemRoot%\system32\himem.sys
files=40

, FILES 40,
.
.
Ctrl+Shift.

, , MS-Windows
Vista. , .
, ,
D:\Lang\BP\Rus. RK.COM ( RK-866.COM),
C:\Windows\System32:
CONFIG.NT AUTOEXEC.NT.
AUTOEXEC.NT .

544


IDE Borland Pascal
LH d:\Apps\Lang\BP\Rus\Rk-866.com /R5

LH d:\Apps\Lang\BP\Rus\Rk-866.com /R5

IDE :
.
(. 167).

. 167

(. 168) CONFIG.NT
AUTOEXEC.NT.

. 168 MS-DOS

, , , ,
, .
545


IDE Borland Pascal
D:\Lang\BP\Rus\Config.nt
D:\Lang\BP\Rus\Autoexec.nt

OK . ,
, IDE.
MS-DOS ,
.
. IDE MS-Windows XP
(. 169).

. 169

, .

Turbo Pascal School Pak


, IDE .
: ,
Turbo Pascal School Pak (
, ).
? :
IDE Borland Pascal ;
;
;
.
DOSBox (
MS-DOS). ,
Norton Commander. DOSBox:
,
Alt+F11.

546


Delphi
, , Delphi
. ,
.


Borland Delphi
Project1 .
.
1) File New Other (. 170).

File New Other

. 170 File New Other

2) New,
Console Application, OK (. 171).

547


Delphi

New

Console
Application

. 171

.
program Project1;
{$APPTYPE CONSOLE}
uses

SysUtils;

begin
{ TODO User Console Main : Insert code here }
end.

Project1,
CONSOLE, , USES.
, BEGIN END ,
, .



.
1) Project Options (. 172).

548


Delphi

Project Options

. 172 Project Options

2) Compiler
, . 173.
Borland Pascal. OK
Default,
.

549


Delphi

Compiler

. 173 , Compiler

3) File Save
File Save Project As (. 174)

Save

Save Project As

. 174

550


Delphi

()
.
DPR ( PAS, Borland Pascal).
!
( Program).
, .
, ,
. , My_Prj_1
.
program My_Prj_1;
{$APPTYPE CONSOLE}
uses

SysUtils;

begin
{ TODO User Console Main : Insert code here }
end.

.
F9.


Delphi ,
Borland (Free) Pascal.
( , !). ,
.
program My_Prj_1;
{$APPTYPE CONSOLE}
uses

SysUtils;

begin
Writeln('Hello, World!');
Writeln(', !');
Readln;
end.

.
.
,
.
.
, Rus,
551


Delphi

. ,
.
program Project_Rus;
{$APPTYPE CONSOLE}
uses

SysUtils,

Windows;

function Rus(const msg: string): string;


var s : AnsiString;
begin
s:= msg+#0;
CharToOem(PChar(s), PChar(s));
Rus:= s;
end;
begin
Writeln(Rus(', !'));
Readln;
end.

USES
Windows. , Rus
, . .
1) File New Unit,
.
unit Unit1;
interface
implementation
end.

2) File Save ,
, , Russian. ,
,
PAS.
3) Rus
Russian.pas. Rus INTERFACE,
USES Windows, Russian.pas
.

552


Delphi
unit Russian;
interface
function Rus(const msg: string): string;
implementation
uses Windows;
function Rus(const msg: string): string;
var s : AnsiString;
begin
s:= msg+#0;
CharToOem(PChar(s), PChar(s));
Rus:= s;
end;
end.

Ctrl+S.
4) Rus, USES
Windows Russian. .
program Project_Rus;
{$APPTYPE CONSOLE}
uses

SysUtils, Russian;

begin
Writeln(Rus(', !'));
Readln;
end.

5) F9.

Russian USES .

553


IDE Pascal ABCNet
Pascal ABCNet
, . ,
. IDE ,
, .
IDE Pascal ABCNet ,
http://pascalabc.net.
IDE.
IDE ,
(. 175).
, .

. 175 - IDE Pascal ABCNet

F9
.
, ,
(. 176).
. Enter
554


IDE Pascal ABCNet

. ,
Ctrl+F2.

. 176 -


, .
(. 177), (
).
IDE Pascal ABCNet , ,
IDE Borland Pascal , .
Net ,
.

555


IDE Pascal ABCNet

. 177 -

, , IDE Assigned.
.
function Assigned (p: pointer): boolean;
begin
Assigned:= p <> nil
end;

Pascal ABCNet,
.
FillChar.
.
, ,
, .
, ( UNICODE).
, (
) .

556



, .

AND

ARRAY

ASM

BEGIN

CASE

CONST

CONSTRUCTOR

DESTRUCTOR

DIV

DO

FOR, WITH, WHILE

DOWNTO

FORDOWNTODO

ELSE

EXPORTS

IF, CASE
BEGINEND, CASEEND,
ASMEND, RECORDEND
DLL

FALSE

FILE

FOR

FORTODO

FUNCTION

GOTO

IF

IFTHENELSE

IMPLEMENTATION

IN

INHERITED

INLINE

INTERFACE

LABEL

LIBRARY

MOD

NIL

END

557

NOT

OBJECT

OF

CASEOFEND

OR

PACKED

()

PROCEDURE

PROGRAM

RECORD

SET

RECORDEND

REPEATUNTIL
SETOF

SHL

SHR

STRING

THEN

IFTHENELSE

TO

FORTODO

TRUE

TYPE

UNIT

USES



REPEATUNTIL

VAR

WHILE

WHILEDO

WITH

WITHDO

XOR

( )

REPEAT

UNTIL

558

,
.

Borland Pascal

ABSOLUTE

ASSEMBLER

EXPORT

EXTERNAL

FAR

FORWARD

INDEX

DLL

INTERRUPT

NAME

DLL

NEAR

PRIVATE

PUBLIC

RESIDENT

DLL

VIRTUAL

559


(Borland Pascal)

Out of memory


.

MS-DOS.

Identifier expected


. ,

.

Unknown identifier

( )
.

Duplicate identifier

Syntax error

(
).

Error in real constant

Error in integer constant

String constant exceeds line


(255 ).
,
.

10

Unexpected end of file

.
,
begin end,
.

11

Line too long


( 127 ).

12

Type identifier expected

13

Too many open files


,
.

FILES=NN
CONFIG.SYS.

14

Invalid file name

560


(Borland Pascal)

15

File not found

,
.

16

Disk full

,
.

17

Invalid compiler directive

,
.

18

Too many files

19

Undefined type in pointer


def

-
.

20

Variable identifier expected

21

Error in type

22

Structure too large


65520 .

23

Set base type out of range

- 256

0..255.

24

File components may not be


files or objects

25

Invalid string length

( 255
).

26

Type mismatch


,
.

.

27

Invalid subrange base type

-
.

28

Lower bound > than upper


bound

- ,
.

29

Ordinal type expected

30

Integer constant expected

31

Constant expected


.
561


(Borland Pascal)

32

Integer or real constant


expected

33

Pointer Type identifier


expected

34

Invalid function result type

35

Label identifier expected

36

BEGIN expected


BEGIN.

37

END expected


END.

38

Integer expression expected

39

Ordinal expression expected

40

Boolean expression expected .

41

Operand types do not match

42

Error in expression

, (,
).

43

Illegal assignment

44

Field identifier expected

45

Object file too large

64
.

46

Undefined EXTERN

47

Invalid object file record

, -, .

48

Code segment too large

65520
.

49

Data segment too large

65520
.

50

DO expected


DO.

Invalid PUBLIC definition


PUBLIC ,
.

51

562


(Borland Pascal)

52

Invalid EXTRN definition


EXTRN ,
.

53

Too many EXTRN


definitions

EXTRN.

54

OF expected


OF.

55

INTERFACE expected


INTERFACE.

56

Invalid relocatable reference


, .

57

THEN expected


THEN

58

TO or DOWNTO expected


TO DOWNTO

59

Undefined forward


FORWARD,
.

61

Invalid typecast

.


.

62

Division by zero

63

Invalid file type

64

Cannot read or write


variables of this type


Read, Readln, Write, Writeln.

65

Pointer variable expected

66

String variable expected

67

String expression expected

68

Circular unit reference

.

(USES) IMPLEMENTATION.

69

Unit name mismatch

,
, .
563


(Borland Pascal)

70

Unit version mismatch



( ).

.

71

Internal stack overflow


- .

72

Unit file format error


. ,
.

73

Implementation expected

74

Constant and case types


don't match

75

Record or object variable


expected

76

Constant out of range

77

File variable expected

78

Pointer expression expected

79

Integer or real expression


expected

80

Label not within current


block

81

Label already defined

82

Undefined label in preceding ,


stmt part
.

83

Invalid @ argument


@.

84

UNIT expected


Unit.

85

";" expected

86

":" expected

87

"," expected

88

"(" expected


.
564


(Borland Pascal)

89

")" expected

90

"=" expected

91

":=" expected

92

"[" or "(." expected

93

"]" or ".)" expected

94

"." expected

95

".." expected

96

Too many variables



64.

97

Invalid FOR control variable FOR.

98

Integer variable expected

99

Files types are not allowed


here

String length mismatch

101

Invalid ordering of fields

102

String constant expected

103

Integer or real variable


expected

104

Ordinal variable expected

105

INLINE error


Inline.

106

Character expression
expected

107

Too many relocation items

.
.

100

565


(Borland Pascal)

108

Overflow in arithmetic
operation

109

No enclosing For, While or


Repeat statement

Break Continue
For, While
Repeat.

110

Cannot run a unit

,
,
.

111

Compilation aborted

112

CASE constant out of range

CASE
-32768 32767

113

Error in statement

114

Cannot call an interrupt


procedure

116

Must be in 8087 mode to


compile

Single, Double, Extended Comp



.

Target address not found

Search |
Find error
.

118

Include files are not allowed


here

,
{$I filename}.

.

119

No inherited methods are


accessible here

inherited

,
.

121

Invalid qualifier

,
,
.

122

Invalid variable reference

,
, .

Too many symbols


, 64 .
.

117

123

566


(Borland Pascal)

124

Statement part too large

24 .

.

126

Files must be var parameters


VAR.

127

Too many conditional


symbols

128

Misplaced conditional
directive

130

Error in initial conditional


defines

131

Header does not match


previous definition


,
FORWARD,
.

133

Cannot evaluate this


expression


,
.

134

Expression incorrectly
terminated

135

Invalid format specifier

136

Invalid indirect reference

137

Structured variables are not


allowed here

138

Cannot evaluate without


System unit

Turbo.tpl
System.

139

Cannot access this symbol

140

Invalid floating-point
operation

141

Cannot compile overlays to


memory

, ,
.

142

Pointer or procedural
variable expected

143

Invalid procedure or
function reference


. ,
{$F+}.
567


(Borland Pascal)

Cannot overlay this unit


,
{$O+}.

146

File access denied


(, ,
, ,
).

147

Object type expected

148

Local object types are not


allowed


().

149

Virtual expected

150

Method identifier expected

151

Virtual constructors are not


allowed

152

Constructor identifier
expected

153

Destructor identifier
expected

154

Fail only allowed within


constructors

Fail ,
.

155

Invalid combination of
opcode and operands

156

Memory reference expected

157

Cannot add or subtract


relocatable symbols

158

Invalid register combination

159

286/287 instructions are not


enabled


80286/80287.

160

Invalid symbol reference

162

ASM expected


ASM.

144

568


(Borland Pascal)

Invalid function number

MS-DOS.

File not found

Path not found

Too many open files

.


CONFIG.NT (CONFIG.SYS).

File access denied

Invalid file handle

12

Invalid file access code

15

Invalid drive number

() .

16

Cannot remove current


directory

17

Cannot rename across


drives

18

No more files

FindFirst FindNext
.

100

Disk read error

101

Disk write error

( ) .

102

File not assigned

,
Assign.

103

File not open

104

File not open for input

105

File not open for output

106

Invalid numeric format

150

Disk is write-protected

151

Bad drive request struct


length

, .

152

Drive not ready

154

CRC error in data

.
569


(Borland Pascal)

156

Disk seek error

- .

157

Unknown media type

158

Sector Not Found

159

Printer out of paper

160

Device write fault

161

Device read fault

162

Hardware failure

-.

200

Division by zero

201

Range check error

202

Stack overflow error

203

Heap overflow error

204

Invalid pointer operation

Dispose FreeMem
.

205

Floating point overflow

206

Floating point underflow

207

Invalid floating point


operation

208

Overlay manager not


installed

209

Overlay file read error

210

Object not initialized

211

Call to abstract method

212

Stream registration error

213

Collection index out of


range

214

Collection overflow error .

215

Arithmetic overflow
error

216

General Protection fault

570




(Runtime errors)

$R

Range Checking

$S

Stack Checking

$I

I/O Checking

-.

$Q

Overflow Checking

,
(Syntax options)

$V

Strict Var Strings

$B

Complete Boolean Eval

$X

Extended Syntax


(
).

$T

Typed @ operator

$P

Open parameters

571

$DEFINE NNN

NNN,

$IF

$UNDEF NNN

NNN.

$IFDEF NNN

,
NNN .

$ELSE $ENDIF.

$IFNDEF NNN

,
NNN .

$ELSE $ENDIF.

$IFOPT

,
() .

$ELSE $ENDIF.

$ELSE

,
,
.
$ENDIF.

$ENDIF

572


Borland Pascal
IDE Borland Pascal.

MS-DOS

Borland Pascal

573


Borland Pascal

574


Borland Pascal

(Ctrl+F8)

575


Borland Pascal


Borland Pascal

576


Borland Pascal


Pascal

577


MS-DOS
(031)

0
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

NUL
SOH
STX
ETX
EOT
ENQ
ACK
BEL
BS
HT
LF
VT
FF
CR
SO
SI
DLE
DC1
DC2
DC3
DC4
NAK
SYN
ETB
CAN
EM
SUB
ESC
FS
GS
RS
US

()
( )



( )








578


MS-DOS

32127

32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

!
"
#
$
%
&
'
(
)
*
+
,
.
/
0
1
2
3
4
5
6
7

56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79

8
9
:
;
<
=
>
?
@
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O

579

80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103

P
Q
R
S
T
U
V
W
X
Y
Z
[
\
]
^
_
`
a
b
c
d
e
f
g

104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127

h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
{
|
}
~
Del


MS-DOS

128255 ( 866 MS-DOS)

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

. 128-255
.

580




Assign(F, Name)

F Name.
F
.
;
.

Reset(F)
Rewrite(F)

Write(F, )


.
TRUE,
.
TRUE,
.

Writeln(F, )
Eoln(F)
Eof(F)
Read(F, )

, .

Readln(F, )

Close(F)

F.


Random(N)

0 N-1

Randomize

Random
.


Length(S)

Pos(S1, S2)

S1 S2

Insert(S1, S2, Index)


Copy(S, Index, Count)
Delete(S, Index, Count)
UpCase(Ch)

S1 S2
Index
S, Index
Count
S, Index
Count

581


SizeOf()
FillChar(X, Size, Val)

,
( )
X Val. Size
.


Ord(X)

Char(N)

Succ(N)

Pred(N)

Inc(N)

Dec(N)


Trunc(R)

Round(R)


New(P)

Dispose(P)

MemAvail

MaxAvail

582

P_05_1

P_07_1

P_08_1

P_09_1

P_09_2

( )

P_09_3

P_10_1

, 1

P_10_2

, 2

P_11_1

, 3

P_12_1

, 1

P_12_2

, 2

P_12_2

, 3

13

P_13_1

( )

14

P_14_1

, 1

P_15_1

, 1

P_15_2

, 2

P_15_3

, 2

16

P_16_1

-, 1

17

P_17_1

, 3

P_18_1

, 1

P_18_2

, 2

P_19_1

P_19_2

P_20_1

()

P_20_2

22

P_22_1

23

P_23_1

10
11
12

15

18
19
20

583

23

P_23_2

24

P_24_1

( )

P_25_1

, 1

P_25_2

, 2

P_26_1

P_26_2

P_27_1

P_29_1

, 1

P_29_2

, 2

30

P_30_1

( )

31

P_31_1

( )

P_37_1

P_37_2

P_37_3

, 1

P_37_4

, 2

P_38_1

, 3

P_38_2

P_38_3

P_38_4

P_40_1

-, 2 ( )

P_40_2

, 3 ( )

P_40_3

P_41_1

P_41_2

P_41_3

, 1

P_42_1

P_43_1

P_43_2

P_43_3

25
26
27
29

37

38

40

41
42
43

584

44

45
46
47
48
49
50
51
53

54

55
56
57
58
59

P_44_1

P_44_2

PASCAL

P_44_3

Pascal

P_45_1

, 1

P_45_2

P_46_1

P_46_2

P_47_1

P_47_2

P_48_3

P_49_1

P_49_2

P_50_1

, 2

P_50_2

, 3

P_51_1

P_51_2

P_53_1

P_53_2

P_54_1

P_54_2

P_54_3

P_54_4

P_55_1

P_56_1

P_56_2

, 2

P_57_1

P_58_1

P_58_2

P_59_1

( MyLibr)
585

59

61

MyLibr

P_59_1

P_61_1

Turbo Vision

P_61_2

P_61_3

586



XVII ()
2004 .

N ,
1 N. M
, 1 M.

, . ,
: .
;
, , .

4
4

3
6


, ,
( ). ,
.


N (2 N 100) M (1 M 30000). M
.
, : ; ,
; (1
2 ). ,
587

.
,
( )

output.txt
.
.

4
1
2
3
5
4
6
1

1
2
2
5
4

6
2
2
1
2
2
4
4

1
1
3
4
3
3

1
2
1
2
2
1

588


1. . . .
. : , 1995.
2. . ., . . :
. .: , 1999.
3. ., ., .
. .: , 1979.
4. . ., . ., . ., ..
( ). : -
, 1997.
5. . ., . ., . ., . .
. : - , 1995.
6. . ., . ., . ., . .
. : -, 2000.
7. . ., . .
/ . . . /. .: , 1985. 96 .
8. . ., . . .
.: , 1990.
9. . . . .: , 1969.
10. . + =. .: , 1989.
11. . ., . ., . . 100 .
.: , 1993.
12. ., . . .:
, 1991. 720 .
13. . ., . ., . ., . .
. .: , 1990.
14. ., .. Turbo
Pasca 7.0. .: -, 1995.
15. . .
.: , 1979.
16. . ., . ., .. .
1989-1996. .: ABF, 1996.
17. . . . 1-3, .
. .: , 2000.
18. ., ., . : .
.: , 2001.
19. . . . .: ,
1978.

589

20. . ., . .
. , - , 1993.
21. ., ., ., .
. .: , 1997.
22. . . . , , 1993.
23. . . (
): . , - , 1996.
24. . . . .:
, 2001.
25. . ., . . 100 . , -
, 2000.
26. . ., . ., . . .
, - , 1998.
27. .., ..
( 5.5) .: 1992.
28. ., . . . .:
, 1989.
29. . . : , 1999.
30. . C++. .
. . . , -, :
, 2003.
31. . . 7.0: . .: . BHV,
2000. 400 .
32. . . .: , 1982. 288 .
33. .. 7.0. : .:
, 2007, 576 .
34. .. 7.0. .
.: , 2007, 416 .
35. . Borland Pascal: Turbo Vision 2.0
: 1993.
36. . Borland Pascal :
1994.
37. . : . .: , 1995.
38. .. Turbo Pascal 7.0 . .: , 2003.

590