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

12.

8
2014-07-21

, 2010-2014,

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
........................................................................................ 197
31
............................................................................ 210
32
............................................................................... 217
33
....................................................................................... 230
34
..................................................................................... 241
35
....................................................................................................... 248
36
...................................................................................... 256
37
................................................................................... 262
38
......................................................................................... 268
39
().............................................................................. 278
40
................................................................. 288
41
, ! ................................................................................... 294
42
, ............................................................................ 302
43
- ............................................................................... 316
44
.............................................................................................................. 331
45
............................................................................................... 340
46
............................................................................................... 350

47
......................................................................................... 358
48
.............................................................................................. 371
49
........................................................................................... 377
50
() .................................................................... 390
51
................................................................................ 397
52
............................................................................. 407
53
.......................................................................................... 413
54
....................................................................................... 421
55
, , ...................................................................................... 435
56
, .................................................................. 441
57
..................................................................................................... 450
58
! ................................................................................... 463
59
............................................................................................ 480
60
............................................................................................. 496
61
() ..................................................................... 501
62
!................................................................................... 520
IDE Borland Pascal................................................ 529
Delphi........................................................ 547
IDE Pascal ABCNet ............................................................... 554
............................................................................ 557
................................................................................... 560
.................................................................................... 569
....................................................... 571
........................................................................... 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
?........................................................................................................... 31
................................................................................................................................... 31
4
! ................................................................................................ 32
......................................................................................................... 32
IDE Free Pascal .................................................................................................. 33
............................................................................................................... 34
IDE Free Pascal ...................................................................... 35
......................................................................................... 37
................................................................................................................................... 38
5
...................................................................................... 39
.............................................................................................................. 39
................................................................................................................... 39
.............................................................................................................. 40
......................................................................................................................... 41
()................................................................................................ 42
............................................................................................................... 44
................................................................................................................................... 44
?............................................................................................................................... 45
6
.................................................................. 46
.................................................................................................... 46
............................................................................................. 47
5

............................................................................................................. 48
................................................................................................................................... 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
? .............................................................................................................................. 68
10
........................................................................................... 69
! ? .................................................................................................................. 69
.................................................................................................................... 69
................................................................................................................. 70
........................................................................................... 71
................................................................................................................... 72
................................................................................................................................... 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
6

............................................................................................... 93
................................................................................................................................... 94
?............................................................................................................................... 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
................................................................................................................................. 125
?............................................................................................................................. 125
20
: ................................................................................ 127
, ! ................................................................................. 127
....................................................................................................................... 129
..................................................................................................................... 131
.................................................................................................. 132
!................................................................................................... 134
..................................................................................................... 134
................................................................................................................................. 134
?............................................................................................................................. 135
21
............................................................................................................ 136
........................................................................................................................... 136
, ! ............................................................................................................ 138
..................................................................................................... 141
................................................................................................................................. 143
?............................................................................................................................. 143
22
.................................................................................... 144
7

............................................................................................................ 144
................................................................................................ 145
.............................................................................................................. 146
................................................................................................................................. 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
8

.................................................................................................................... 188
.......................................................................................................... 188
................................................................................................................................. 190
29
- .......................................................................................... 191
, 1................................................................................. 191
, 2................................................................................. 194
................................................................................................................................. 196
?............................................................................................................................. 196
30
........................................................................................ 197
?....................................................................................................... 197
................................................................................................................... 198
................................................................................................... 201
..................................................................................................................... 203
....................................................................................................................... 205
............................................................................................ 205
............................................................................................................ 207
................................................................................................................................. 208
?............................................................................................................................. 209
31
............................................................................ 210
................................................................................................................. 210
........................................................................................... 211
...................................................................................................... 212
......................................................................................................................... 213
................................................................................................................................. 216
?............................................................................................................................. 216
32
............................................................................... 217
: ................................................................................... 217
.................................................................................................................. 219
, ........................................................................................... 220
.................................................................................................... 223
......................................................................................................................... 223
.................................................................................................................... 224
.............................................................................................................. 225
........................................................................................................... 228
................................................................................................................................. 228
?............................................................................................................................. 229
33
....................................................................................... 230
.................................................................................. 230
............................................................................................. 231
............................................................................................... 231
....................................................................................... 233
.............................................................................................. 233
......................................................................... 235
............................................................................. 237
................................................................................................................................. 239
?............................................................................................................................. 239
34
..................................................................................... 241
.................................................................................................. 241
....................................................................................................... 242
....................................................................................... 243
................................................................................. 244
.................................................................................. 246
9

? ...................................................................................................................... 246
................................................................................................................................. 246
? ............................................................................................................................ 247
35
....................................................................................................... 248
................................................................................................. 248
, .................................................................... 248
...................................................................................... 249
........................................................................................................ 252
, .................................................. 254
................................................................................................................................. 254
? ............................................................................................................................ 255
36
...................................................................................... 256
...................................................................................................... 256
.................................................................................. 256
................................................................................................. 257
........................................................................................................ 258
( IN)....................................... 259
......................................................................................... 259
................................................................................................................................. 260
? ............................................................................................................................ 261
37
.................................................................................. 262
............................................................................... 262
.............................................................................. 263
, ............................................................................. 264
, ............................................................................. 266
................................................................................................................................. 267
? ............................................................................................................................ 267
38
........................................................................................ 268
, ! ................................................................................................... 268
.................................................................................................. 268
....................................................................................................... 270
.......................................................................................................... 273
, ............................................................................................................ 275
................................................................................................................................. 276
? ............................................................................................................................ 276
39
().............................................................................. 278
................................................................................................................ 278
? .......................................................................................... 280
......................................................................................................... 280
....................................................................................................... 281
() ................................................................................... 284
.................................................................................................... 285
......................................................................................................... 285
................................................................................................................................. 287
? ............................................................................................................................ 287
40
................................................................. 288
- .............................................................................. 288
................................................................... 289
........................................................................................................ 291
................................................................................................................................. 293
? ............................................................................................................................ 293
41
, !................................................................................... 294
10

............................................................................................... 294
.................................................................................................. 295
........................................................................................................ 297
.................................................................................... 299
................................................................................................................................. 301
?............................................................................................................................. 301
42
, ............................................................................ 302
, ?............................................................................................. 302
................................................................................................. 302
................................................................................................................ 303
...................................................................................... 306
, , ! .............................................................................................................. 312
? !.................................................................................................. 313
................................................................................................................................. 315
?............................................................................................................................. 315
43
- ............................................................................... 316
........................................................................................................ 316
.......................................................................................................... 318
....................................................................................... 320
............................................................................................................ 323
, !........................................................................................................ 324
................................................................................................................................. 330
?............................................................................................................................. 330
44
.............................................................................................................. 331
........................................................................................... 331
......................................................................................................... 332
...................................................................................................... 333
....................................................................................................... 337
.......................................................................................................... 337
................................................................................................................................. 338
?............................................................................................................................. 338
45
............................................................................................... 340
................................................................................................ 340
...................................................................................................... 341
.............................................................................................. 345
........................................................................................................ 346
................................................................................................................................. 349
?............................................................................................................................. 349
46
............................................................................................... 350
? ..................................................................................................... 350
........................................................................ 350
................................................................................................................ 351
........................................................................................................ 353
................................................................................................................................. 356
?............................................................................................................................. 357
47
......................................................................................... 358
................................................................................................................... 358
.................................................................................................. 358
.......................................................................................................... 360
............................................................................................................. 363
............................................................................................ 364
............................................................................................... 366
11

........................................................ 366
................................................................................................ 368
................................................................................................................................. 369
? ............................................................................................................................ 369
48
.............................................................................................. 371
................................................................... 371
................................................................................... 372
..................................................................................................... 375
................................................................................................................................. 376
? ............................................................................................................................ 376
49
........................................................................................... 377
............................................................................................................ 377
................................................................................................ 377
- .............................................................................................................. 382
................................................................................................................................. 388
? ............................................................................................................................ 389
50
() .................................................................... 390
! ................................................................................................................ 390
............................................................................................................................... 390
...................................................................................................................... 391
..................................................................................................... 394
................................................................................................................................. 396
? ............................................................................................................................ 396
51
................................................................................ 397
................................................................................. 397
....................................................................................................... 398
, ......................................................................................... 399
.................................................................................................... 400
, .................................................................... 401
.................................................................................... 402
............................................................................................... 403
..................................................................................................... 403
.................................................................................................... 404
................................................................................................................................. 406
? ............................................................................................................................ 406
52
............................................................................. 407
................................................................................................ 407
!........................................................................................... 407
............................................................................................................ 408
...................................................................................................... 408
, .................................................................................. 409
................................................................................................................................. 411
? ............................................................................................................................ 411
53
.......................................................................................... 413
........................................................................................................ 413
....................................................................................... 418
................................................................................................................................. 419
? ............................................................................................................................ 420
54
....................................................................................... 421
.......................................................................................................... 421
.................................................................................................. 422
................................................................................................................... 422
12

............................................................................................................. 426
.................................................................................... 427
..................................................................................................... 428
........................................................................................ 432
................................................................................................................................. 433
?............................................................................................................................. 434
55
, , ...................................................................................... 435
.................................................................................................. 435
................................................................................................................... 435
.............................................................................................................. 435
........................................................................................................................... 436
?............................................................................................................................. 440
56
, ................................................................... 441
?............................................................................................................. 441
! ..................................................................................................................... 444
................................................................................................................................. 449
?............................................................................................................................. 449
57
...................................................................................................... 450
......................................................................................... 452
..................................................................................... 453
........................................................................................................... 456
................................................................................................................................. 462
?............................................................................................................................. 462
58
!.................................................................................... 463
........................................................................................................... 463
.................................................................................................................. 468
! .................................................................................................................... 469
- ........................................................................................................................... 475
................................................................................................................................. 478
?............................................................................................................................. 478
59
............................................................................................ 480
......................................................................................... 480
.............................................................................................................................. 481
.................................................................... 481
......................................................................................................... 486
..................................................................................................... 487
............................................................................................................. 490
........................................................................................................... 490
.................................................................................................................. 492
.................................................................................................... 493
(DLL) ............................................................... 494
................................................................................................................................. 495
?............................................................................................................................. 495
60
............................................................................................. 496
.......................................................................................................... 496
....................................................................................................... 497
................................................................................................................................. 500
?............................................................................................................................. 500
61
()...................................................................... 501
- ...................................................................................................................... 501
............................................................................................................. 502
.................................................................................................................... 502
13

................................................................................................................... 503
.................................................................................................................... 505
.............................................................................................................. 506
............................................................................................. 507
.................................................................................................... 512
................................................................................................................... 513
.............................................................................................. 516
................................................................................................................................. 518
? ............................................................................................................................ 518
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
................................................................................... 560
.................................................................................... 569
....................................................... 571
........................................................................... 573
MS-DOS .............................................. 578
.......................................... 581
..................................................................................... 583
..................................................................... 587
....................................................................................................................... 589

14


, ,
, .


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

?
:

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

. , ,
.

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


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



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

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

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

?
, , ? .
.
1- 4-
.
.
5- 31-
.
.
32 35
.

17

36 58
. , ,
.
59 60 ,
61 - .
62-
.
, , - ,
, .
, ,
,
. ,
? . , ,
,
. : 1) , 2) ,
3) . . ,
, .
,
,
. .
.
: !

. , .
, -
? , ,
!

,
, !
freepascal.ru, ,
.
, : oleg.derevenets@gmail.com
:
http://oleg-derevenets.narod.ru

18

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

. , ,
, , . ,
, .
,
. , .
, .
Delphi.
,
. ,
. ,
!
19

1

, ,
? , ? ,
, .

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

Windows, .

, , ?
, .
, ,
. 4- ,
Windows.


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

20

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


.
, ,
.
,
. (
). :
http://freepascal.ru ;
http://ptaskbook.com/ru/tasks/index.php .
62- ,
.



. , ,
, .
? ? ?
, .
.

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


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

,
:
Borland

, ,
..;

File Name

Begin

().

F9

.
, .

.
.
,
Windows.
,
.
, ,
, .

.
!

22

2

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


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


, ,
EXE. , ?
, Total Commander.
23

, F3
(. 1).

. 1

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


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

24

,
,

EXE-,
,

EXE-
( )

. 2

?
,
. ,
, . ,
, , .
, , .
, , , (
Source ).
. .
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.
.


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

MS-DOS

, (. 3).

. 3 ( )

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

. 4 DIR

, ,
. DIR
. CLS ( ),
, .
EXIT () , .

, , Windows
. Alt+Enter,
Windows. ,
(Vista, Windows-7)
.
,
: , , ,
.. , :
VER

MEM

TREE

HELP

,
5, .

30

?
,

Delphi Lazarus, :
?
Delphi !
, IDE Delphi .

. ,
. .
.
,
. ,
, ? ,
, .

,
, , .

, .
, .

31

4
!
,
, (IDE).
, , .


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

Net, Microsoft. ABC
, .
32

4
!

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

Borland Pascal;

Delphi;

Pascal ABCNet.

IDE Free Pascal


IDE Free Pascal.
, . ,
www.freepascal.org. Downloads,
- .
Intel
Windows
www.freepascal.org/down/i386/win32.var
,
( SourceForge,
).
fpc-2.6.0.i386-win32.exe
, ,
. , ,
. IDE
C:\FPC\2.6.0 ( 2.6.0),
IDE. ,
c:\fpc\2.6.0\bin\i386-win32\fp.exe

33

4
!


, , ,
. ? ,
, . :
, .
. , , :
C:\User\Pascal
, IDE, .

. ,
, ,
(. 5 ).

. 5 -

(. 5 )
, !
OK.

34

4
!

IDE Free Pascal


. IDE
.
, (. 6).

. 6 -

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

. 7 -

(. 8).
Video mode . ,
80x25 color ,
30 .
35

4
!

, . 8. OK
.

. 8 -

IDE Free Pascal , . 9. FPC


Free Pascal Compiler
.

. 9 - IDE Free Pascal

IDE , .
, . ,
,
, .

36

4
!


,
:
http://freepascal.org/docs.var

PDF;

http://freepascal.org/down/docs/docs.var

HTML CHM.

. ,
http://freepascal.org.
doc-html.zip, .
HELP ,
IDE Free Pascal, zip- .
fpctoc.html,
.
IDE Free Pascal,
.
IDE Help Files (. 10).

. 10 -

(. 11).

. 11 -

37

4
!

New fpctoc.html, IDE


.
,
fpctoc.htx. fpctoc.htx ,
(. 12).

. 12 -

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

Free Pascal
Free Pascal
,
fp.cfg fp.dsk.

(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),

. ,
1- 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 -
END. END
, .
()
() , : Begin, BEGIN, begiN, .
, .
, .
:
(, , ), ,
!
END,
. ,
END, , , .
, , F2
. , IDE
, .
.
PROGRAM, .
, :
program P_05_1;
begin
end.

.
, !
, , .
, ,
! , .

? ? ,
EXE- F9.
, (. 15).
41

. 15

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

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

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

Writeln, -
. , ? ,
. !,
( ).
, , .
:
, !
--- Free Pascal ---
, !

, ,
.
, , .
255 , .
, :



?
, :

, ,
, !
, , :
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 , IDE
.

46


, Windows, IDE
Free Pascal . . 18,
.

(1-9)

( : )

. 18

. ?
. ,
.

.

? ,
;
F2 File 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

?
? !
, .
.
. , ,


.
. ,
.
, . ?
. , ,
.
,
, .
, , .
?
.
,
.
, .
:
, .
.
, , ,
. CONST,
, .
const _ = _;

, .
, Line .
.

56

8

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

, ,
!
, .
Writeln(Line);

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

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

--, . ,
.
? :
const

Line = ***************************;

-.

. , ,
!
57

. ,
, .
(IDENTIFIER).
, .
.
,
.
, (
!).
127 , ( Borland Pascal
63 ).
.
.
( ),
Pascal PASCAL .
:
A, b, C

R1, U28, _13_

Cosmos, ABBA

NextStep, Next_Step

- ,

:
7Up

End

, ,
. ,
C (, CLine).

, P_07_1
, .
: ,
. :

58

8

?

,
Enter

.
.
, .
,
.
, ,
. -
(, ).
? , , .
(VARIABLE).
, .
,
. : , .
, , . ,
, ,
!
, , , , .
,
VAR ( VARIABLE),
BEGIN.
. :
, :
var

_ : _;

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

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

Name : string;

, ,
.


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

,
Enter. , ,
Name .
, , Enter.
?
Writeln? ! .
:
Writeln(Name);

, !
, .
? !
, , .
:
60

8

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;
S : string;

N S Name ()
Surname ().
, .
var

N, S : string;

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

? ! :

63

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

Writeln !
: ,
, .
.
var

N, S : string;

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


, .
, , ,
.
, .
A := ', !';

B := A;

A B

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

Writeln(B);

B:= A;
Writeln(B);

Readln

end.

, .
64

9
:


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


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

. 22 +

. 22 . +
, .
R ,
( N S ,
).
R:= , + N + + S + !;

, :=
, .

.

65

9
:
var

N, S, R : string;

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


, ( !).
var

S : string;

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

S . , ,
Writeln(S)? !
. ,
, .
.
,
.
: , , -
! , , .
: Readln,
.
S ,
.
S:= S + !;

S .
!. ,
, . !
66

9
:


- .
, , .
, :
const Pele = ;

(string)

Number = 12;

, .

, :
const Pele : string = ;

(string)
(integer)

Number : integer = 12;

,
.
,
.
Delphi :
var

Pele : string = ;

Borland Pascal, .

.
Writeln
. .
:= ,
, ,
.
.

Readln, .
, ,
.

67

9
:

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

Readln;

end.

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

B:=456;

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

Readln;

end.

) ?
const Pele = ;

) , : ,

, .
:
:

: : :

:
Writeln, .
) ?
const
Pele = ;
ABBA : string = ;
var
Moscow : string;
begin
Pele

:= ;

ABBA

:= ;

Moscow:= ;
end.

68

10

, ,
. ,
.

! ?
, . ,
, pascal. ,
. P_10_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 .
,
: 1) ,
2) 3) .
. - (. 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 -

71

10



P_10_2.
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( !);

. , ?
.
, , ?
75

11

IF-THEN-ELSE, !
,
.
, ?
, - .
! ,
, .
BEGIN END.
.
if S = pascal
then begin
Writeln( !);
Writeln(, !);
Writeln(!)
end
else begin
Writeln(!);
Writeln( !)
end;

, BEGIN-END
.
BEGIN-END? !
, . ,
, : .
BEGIN-END, .
, .
: END ?
! , ,
END .


, , THEN ELSE
. , ? .
, .
?
.
; . ,
, , .
76

11

.
?
THEN ELSE,
. , , .
BEGIN END ,
.
,
, , . , ,
P_11_1,
, begin-end .
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

.
.

-.
?
. , ,
. ,
, .
, .
.
,
.
A:= B;

//

BEGIN-END
. .

. , .
.
.
.

?
) ?
) ,

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

78

12


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

:
!

:
!

. 27 -

, ,
, , .
, -, ,
-, .
. ,
! !.
, S,
79

12

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

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


, , .
,
.
, : REPEAT
UNTIL .
BEGIN-END,
.
? REPEAT ,
UNTIL , .
REPEAT
< 1>;
< 2>;
. . .
< N>
UNTIL

- :
, . . 28 -
; 1 2
, .
, 3.
. BEGIN-END ,
REPEAT-UNTIL
. , .

80

12

REPEAT

UNTIL

. 28 -

.
P_10_1.
REPEAT-UNTIL ,
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.PAS,

, !
, , . ,
.
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.

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

?
) REPEAT UNTIL?
) UNTIL ?
) P_11_1

. ?
) .

, , .

85

13

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

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


, . ,
, , ?
-, : ,
. , ,
, , ,
.
.
, ? ,
: .
(- BIT).
: , 1
( ) 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;
Writeln(B);

Readln;

end.

? , .



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

13

.
:
B := S=1;

if S=1 then B:= true else B:= false }

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

, if B then... if B=TRUE then....


? ,
,
.


, ,
.
.
, ,
. ,
TRUE, FALSE. ,
, .
,
(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 ().
C

. 34 ,

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

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

13

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

, . 35, .
, TRUE ( ,
).

A=TRUE

. 35 ,

, : ,
. ,
NOT. .
if not A
then S:= !
else S:= !;

,
, .
, .


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

93

13

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 ().
OR, AND, NOT
.
.
.

94

13

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

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

) . 36.
F

. 36

) M1, M2 M3 ,

TRUE , FALSE .
, TRUE :
;
;
;
, ;
, .
: ;
, ,
: M1 and (M2=M3).

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 2;

{ =5 }

M := 10 mod 2;

{ =0 }

N := 10 div 3;

{ =3 }

M := 10 mod 3;

{ =1 }

N := 10 div 4;

{ =2 }

M := 10 mod 4;

{ =2 }

N := 10 div 5;

{ =2 }

M := 10 mod 5;

{ =0 }

N := 10 div 6;

{ =1 }

M := 10 mod 6;

{ =4 }

,
, .

(=), (<>), (>), (<), (>=),
(<=). , , ,
:
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?
. ?
) : A, B C,

. : ,
, :
if (A>=B) and (A>=C) then . . .

. ,
, .
48.
) A B.

, X, Y, Z.
:
, A<B X<Y<Z.
,
, , .
) A B.

(A1, B1 A2, B2),


, .
.

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
. ,
Randomize ,
.
{ 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);
Random(5) + Random(5) + Random(5) + Random(5);
!
) ?
.
var x : integer;
begin
repeat
x := Random(20);
Writeln(x);
until x=1;
end.

) Randomize?

? ?
) (False,

True), 20 . :
.
) ( 1 10) ,

. .

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:= ;
3: 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, .


CASE-OF-ELSE-END.
CASE ,
.
( ).
CASE
. ,
, ELSE. ELSE ,
.

BEGIN-END.

109

16
,

?
) , CASE

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

: - ,
: 20 , 34 , 41 . :
MOD 10.
, (, 11, 12, 13, 14).
) 1 12,

: , , , .
: , :
case N of
1, 2, 12 : Writeln();

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

, ).
, ,
( 1 8).
, .
) :
( 1 8), .
, .
, .

: 1- 1- .

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 .
. ,
,
(), .
(3..5) .

FOR-TO-DO
, .
,
, .
CASE-OF-ELSE-END
, .

?
) .

.
( Break).
) ,

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

= 7

= 20
!

.
) , , N, 1

N , :
114

17

N = 3
3
2
1

) FOR, ,

, :
FOR N:= _ DOWNTO _ DO
DOWNTO (DOWN );
,
.
( ).
) N M,

(*). :
N M.
) , 1 N, N

, .
) , 1 N,

, .

) P1 P2

(P1<P2). M.
? .
) R1 R2

(R1<R2).
:
P1-P2 ?
P1-P2 ? ,
.
? ,
.

115

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

, ,
.


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

? 14 , ,
, 17.
CHAR
CHARACTER, . , ,
.
.
var c1, c2, c3 : char;

,
, :
c1:= A;

c2:= B;

c3:= c1;

, , . ,
, ,
116

18
,

! ,
.
c1:=ABBA;

{ }

c2:=;

{ ! }


, :
var

c1 : char;

S: string;

. . .
S:= c1;

, !
,
, :
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
, BEGIN-END.
UNTIL,
Length.
. ,
.

119

18
,

.
CHAR.
CHAR
, .
.
, ;
.
,
.
.
Length.

FOR-TO-DO.

?
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];

.
) :

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

120

19
:

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


.
Enter
.
Write( Enter);

Readln;

, . ,
, .
, .
PROCEDURE,
, .
, .
Pause (),
(. 40).
121

19
:

Procedure Pause;

Begin

Write( Enter);
Readln;
End;

. 40 Pause

. ,
BEGIN-END.
. BEGIN-END
, . :
BEGIN-END !
, !
, ? . 41
.
,
BEGIN END.
const . . .
var

. . .

Begin
. . .
End.

. 41

, ,
. ,
, .
Pause ,
.

122

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

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

{ }

end.

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

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

123

19
:

, ,
.
. ,
Enter,
.
begin

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

end.


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

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

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

{ }

begin
Write(msg);

Readln;

end;

,
.
124

19
:

?
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
, .

.
.
,
, .

.
, .

, .

?
) Pause,

, .
.
125

19
:
Pause(true);

{ Enter }

Pause(false);

{ Press Enter }

) ( Line ),

, , :
Line(3);

{ *** }

Line(7);

{ ******* }

: .
) ,

. : (
25, ).
) , ,

.

) ( ),

.
, , .. :
, 112-345-1;
, 1-123-451.
) , N .

.
.
, ,
:
;
;
N- ( ) .

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), , ,
S arg.
130

20
:

,
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
:

,
,
.
,
.

?
) 17- ,

. P_17_1 ,
, .
) , , ,

N, N .
.
) .

A1 B1 ( ),
A2 B2 (, A1<B1 A2<B2). ,
- . ,
3-
. ,
, ,
.
) , ,

. :
.
,
, .
A = true, ;
B = true, ;
C , :
1234567-

;
, ;
, ;
;
, , ;
, ;
, .

135

21

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


.
, .
,
. , -!
: Run
Debug ().
.
Run
(. 45).
Ctrl+F9
F8

F7

F4

Ctrl+F2

. 45 RUN

. Borland Pascal, IDE


Free Pascal .
136

21

. 1 .
. 1 Run

Ctrl+F9

Trace into

F7

().
,
,

.

Step over

F8

.
,
, .

F4

,
, .

!

Program Reset

Ctrl+F2

.
,
.

Parameters...

,

.

Run

Go to cursor

:
, , . ,
, , .
, ,
. ,
.
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

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

()

. 49 Window Tile

,
(. 50). ,
.
,
. Ctrl+F9,
F7 ( Run Trace).
, .
F7
, .
F7 , Readln,
.
QAAAW Enter,
Scan, . 50.
. IDE Free Pascal
Enter .

139

21

. 50 Scan

Watches. k
, k,
. S ,
. arg ,
Unknown identifier.
F7 ,
Scan. arg ,
S, .
F7, END
. , arg
QBBBW, , .
. 51.

. 51 Scan

140

21

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
.
,
: (, ..),
, , .
, :
- ,
.
VAR. , , -,
.
. ,
Ctrl+F2.
, .
Scan, , arg S
(. 53). , , , !

142

21

. 53

,
Ctrl+F9.

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

?
) Ctrl+F8

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

143

22


. ?
,
. , ,
.
.


.
A B, .
T:= A;

{ A }

A:= B;
B:= T;

{ B , A }

T .
, 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]= Ch then Res:= Res+1;
end;

: arg, Ch
Res . .
: , ,
arg .
255 , arg
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; Ch: char; var Res: integer);

, .
Calc(PASCAL, L, Result);

{ }

Calc(S, L, Result);

{ }

CONST , , VAR,
, .
CONST VAR:
, .

,
.
(
)
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;

{ arg }

Scan:= arg;
end;
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 }

,
.
, IF.

(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


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


. :
if X=
then Encrypt:=
else if X=
then Encrypt:=
else . . .

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

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


.
. ,
!
155

24

,
. ,
,
. ?
, , .
, . ?
. , ,
; , 1, 2 .
,
. ,
, , .
:
.
, . ,
, .
256 0
255 . 256, 300 500?
, 256 ,
( , ).
, , ,
,
, , .
,
.
, .
ASCII ( ) American Standard
Code for Information Interchange
. .
, ( MS-DOS)
.
.
0 31.
, 10 13,
.
32 127,
, .
,
32.
, ,
( ) .
156

24

,
. ,
32.
,
(, , , ) !


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

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

', Chr(n))

end.


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

, .
157

24

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

', Ord(c))

end.

FOR .
, ,
.
, ,
.


Encrypt,
.
function Encrypt(arg: char): char;
begin
Encrypt:= Chr(Ord(arg) + CKey);
end;

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

{ }

158

24

function Encrypt(arg: char): char;


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

then x:= x256+32;

Encrypt:= Chr(x);
end;


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

then x:= x+25632;

Decrypt:= Chr(x);
end;


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

then x:= x256+32;

Encrypt:= Chr(x);
end;

159

24

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

then x:= x+25632;

Decrypt:= Chr(x);
end;
{ }
procedure EncryptStr(var arg: string);
var k: integer;
begin
for k:=1 to Length(arg) do
arg[k]:= Encrypt(arg[k]);
end;
{ }
procedure DecryptStr(var arg: string);
var k: integer;
begin
for k:=1 to Length(arg) do
arg[k]:= Decrypt(arg[k]);
end;
{ }
var

S: string;
Oper: integer;

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

{ }

until false;
end.

160

24

.
CKey . ,
.
: Encrypt Decrypt
. EncryptStr DecryptStr
, VAR. , ,

(Oper).
,
! , ?
: pascal
, rcuecn. rcuecn ,
.
: pascal
: 1 , 2 ,
: 1
rcuecn
: rcuecn
: 1 , 2 ,
: 2
pascal
: 1 , 2 ,
: 3

.
.
.

.
256, 32
, .
Chr.
Ord..
, ,
FOR ,
CASE .

161

24

?
) ,

.
:
function EncryptChar(arg: char; key: integer): char;
procedure EncryptStr(var arg: string; key: integer);

, ,
, .
)

,
? ?

( ) . ,
, . ,
PASCAL:
A 2 5
C 4
L 6
p 1
S 3


, , .
, PASCAL:
P 1
A 2 5
S 3
C 4
L 6

) ,

( 9).
. Encrypt
Decrypt , , 32.

162

25

.
.
.


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


, , .
? .

, :
1, 2, ,
3.
. HEX-
, Far, Total Commander .
163

25

111
22
3

(
, HEX- ).
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 ,
.
? , ?
Reset 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);


!
, .
, :
REPEAT-UNTIL;
FOR-TO-DO.
,
:
WHILE <> DO <>
- : ,
-. DO ,
.
BEGIN-END, .

168

25

WHILE

<>

DO

BEGIN

< >

END
, WHILE-DO
REPEAT-UNTIL ! ,
, .
.
{ 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.
: 1)
Assign, 2)
Reset.
Readln,
.

169

25

;
Readln .
, .
.
, Eof,
TRUE, .
,
WHILE-DO.
Close.

?
) F

?
F := c:\autoexec.bat;

) ,

.
) :

;
;
( ).
.
, .
) , ,

. ?
, .
) - ( 16) ,

, .
.
) N- , N

. ,
. :
.

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,
.
, .
InFile OutFile,
.

172

26
, !


InFile

CRYPT.TXT

OutFile

. 57

- (. 58).


(
)



InFile
()



OutFile
()

-
:

. 58 - /

, -
. 59. :
( ).

173

26
, !
-


CRYPT.TXT


CRYPT.TXT

Eof = TRUE

Eof = FALSE

. 59 - -

. ,
? , .
P_24_1. ,
.

174

26
, !
{ P_26_2 }
const CKey = 2; { }
{ }
function EncryptChar(arg: char): char;
var x: integer;
begin
EncryptChar:=arg;
if Ord(arg)>=32 then begin

{ ! }

x:= Ord(arg)+ CKey;


if x>255 then x:= x-256+32;
EncryptChar:= Char(x);
end;
end;
{ }
function DecryptChar(arg: char): char;
var x: integer;
begin
DecryptChar:=arg;
if Ord(arg)>=32 then begin

{ ! }

x:= Ord(arg)- CKey;


if x<32 then x:= x+256-32;
DecryptChar:= Char(x);
end;
end;
{ }
procedure EncryptString(var arg: string);
var k: integer;
begin
for k:=1 to Length(arg) do arg[k]:= EncryptChar(arg[k]);
end;
{ }
procedure DecryptString(var arg: string);
var k: integer;
begin
for k:=1 to Length(arg) do

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

end;

175

26
, !
{----- -----}
procedure

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

const CFixName='CRYPT.TXT';
var

FileIn:

text;

FileOut: text;
S:

{ }

{ }
{ }

string;

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 EncryptString(S)

{ }

else DecryptString(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);

{ }

Write('OK, Enter'); Readln;


end.

176

26
, !

.
Oper
, S. Oper=TRUE
, FALSE . S
. , CryptFile
:
(aFile aOper). a ()
.
,
( ).
}"Rtqi2420rcu"
xct"Ocp"<"uvtkpi=
}///"""///
rtqegfwtg"Rcwug=
dgikp
"""""Ytkvgnp*)"Gpvgt<)+=""Tgcfnp=

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

, ,
TEXT.
:
Assign
Rewrite.
Rewrite ,
( !).
Writeln,
.
Close,
.
177

26
, !

?
) , ,

. .
) .

,
:
:
,
.
,
.

:
1
,
2
.
3
,
4
.

) :

;
(. 25-
).
)

: ,
. , ?
) (.

). ,
.

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

Generated 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
.
.
) ,

.
.
) , (

).
, , .
2+3

, ;

(2+3

()2+3()

( );

))2+3((

: Check,
TRUE, .
) .

- , ,
.
, , 100 . ,
0, 1. ,
, .
.
( ).
,
: ,
, , :

0
1
0
1
1
1
0


0
0
0
0
0
1
1

185

28

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


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

( ).

186

28

/
/

. 62 Window

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

. 63

OK
( ).
Size/Move .
,
.

187

28


, ?
. ,
? ( Copy
Paste ). , ,
, ?
,
.
. :
( );
(Ctrl+Insert);
, (
);
(Shift+Insert).
. , .
.
Shift,
( , ).
: ,
.
, ,
, Ctrl+K+H.
, Windows
. , : IDE Windows
, . ,
Windows, IDE . ,
IDE Edit Show Clipboard.
. IDE Free Pascal Windows Copy to Windows
Paste from Windows, Windows.


,
. ,
.
, ! ,
? , .
Help F1 ,
188

28

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

. 64 IOResult

?
.
.
.
. ,
Enter. .
. 65 Close.
,
. ( Enter),
, .
C ,
: , .
! - ?
,
(Ctrl+Insert, Shift+Insert).

189

28

. 65 Close

, IDE Free Pascal


4. Borland Pascal
.
, BP.EXE,
TURBO.TPH.
, ?

, .
;
, Windows.
.
IDE Windows .
Windows
, , .
Copy to Windows Paste from Windows.
IDE.

190

29
-
, ,
. .

, 1

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

,
IDE. : ,
-
Police.txt. , .
, !
, .
191

29
-

.
,
, .
.
, P_29_1.
.
, : , ,
. ,
TRUE. -.
, , , ,
, .
{ 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 .

192

29
-

FindNumber ( Find ,
Number ). ,
. :
( VAR).
! ,
:
! , aFile F.
a : aFile, aNumber?
? , , ,
. ,
.
.
.
, ()
a ( argument).
.
FindNumber.
FALSE. ,
, ,
, , WHILE
.
. Reset
.
, !
WHILE, ,
.
while not Eof(aFile) and (N<>aNumber)


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

{ true, }

, ( )
. ,
TRUE, . ,
. .
193

29
-
if N=aNumber
then FindNumber:= true
else FindNumber:= false;

, , .
, , .

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

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

194

29
-

Reset

Eoln

123

234

325

Readln

223

240

Eoln

Readln

845

431

205

Eoln

. 66 Readln

, Reset ,
Readln . ,
, , , .
, Readln
, ,
. ! LN
( Line ). : Readln
. ?
, , !
Read ( ),
.
. !
Read . 67.
Read

Read

Reset

Read

123

234

325

223

240

Eoln

845

431

205

Eoln

Eoln

. 67 Read


.
, . ?

195

29
-

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


Read(aFile, N);

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

,
.
.
,
Reset.
Readln
.
.
Read
.
.

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

, ? .

196

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

,
, .

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

, - .
. 68 . ,
, : ,
.

198

30

= 0
,


while

. 68

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

199

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).
200

30

= 0,
= 0

while not Eoln

,
,


?

. 69 -

,
. ,
, .
, .
, , ,
, .
, REPEAT-UNTIL?
. ,
, , !
WHILE .


P_30_1,
. :
,
.
HandleString, .
( ).
201

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;

202

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.

203

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,
. ,
.
204

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);

,
, .
. .


.
, .
,
, :

205

30

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

Cnt
, Sum (
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

. ,
. .

206

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;

!
, .

207

30

12 4.00000000000000E+0000

20 5.00000000000000E+0000

18 4.50000000000000E+0000

10 3.33333333333212E+0000

7 3.50000000000000E+0000

? ,
! ,
,
. ,
( 6,0221401023) 6.022140E+0023.
, , .
,
. ( ,
), ( ).
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, .

208

30


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

?
) Trunc , :
Writeln (Trunc( 12.345 ));

{ 12 }


. .
) , .
var N: integer;
begin

for N:=1 to 20 do Writeln ( :N, N);

end.

) Numbers.txt, 100

0 999 ( ).
: 1) ; 2) ; 3)
.
) ,

,
Numbers.txt . ,
.
W. :
( ) (
).

W
W

. 70 -

209

31


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



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

{ }

S :
S:= S + sym;

, ,
, .
, . 71.

210

31

Repeat
?

. 71


, ! (
) ,
, . ? .
Read ,
. -:
, . ,
(
). - (. 72).
. ( )
, , .
Eoln Eof
SeekEoln SeekEof.
TRUE, ()
: , (
SeekEof). P_31_1 .

211

31

Repeat

Repeat
?

. 72


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

Reset(InFile);

Assign(OutFile,'Journal2.out');

Rewrite(OutFile);

, Journal2.in
, 30- .

212

31

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

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

Sum:14, Rating:11:1);

, ReadFam? ,
(. 72).
.
function ReadFam: string;
var sym: char;
S : string;

{ }
{ }

begin
S:=''; { }
{ }
repeat Read(InFile, sym) until (Ord(sym)>32) or Eof(InFile);
{ }
repeat
if Ord(sym) > 32 then s:= s+sym;
if Eoln(InFile) then Break;
Read(InFile, sym);
until Ord(sym) <= 32;
ReadFam:= S;

{ }

end;

.
.
sym <>

.
( 32), .

, .
Journal2.out? , :

213

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) or Eof(InFile);
{ }
repeat
if Ord(sym) > 32 then s:= s+sym;
if Eoln(InFile) then Break;
Read(InFile, sym);
until Ord(sym) <= 32;
ReadFam:= S;
end;

214

31

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

: integer;

{ , }

Cnt: integer;

{ }

Sum: integer;

{ }

Rating: Real;

{ }

Fam: string;

{ }

begin
Fam:= ReadFam; { }
if Length(Fam)>0 then begin

{ , }

{ }
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, Counter:3, Fam:18,' : ');


end
end;
begin

{--- ---}

Counter:= 0;

{ }

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

Reset(InFile);

{ }
Assign(OutFile,'Journal2.out');

Rewrite(OutFile);

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

215

');
');

31

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

{ }

HandleString;

{ }

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

Close(OutFile);

end.

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

?
)

Police.txt ( ) (
).
) :

, . :
,
175 ;
,
() () 100.

.

216

32

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

:
? ,
. ,
, ,
,
.
. 73 , .
: , .

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

217

32

ShortInt, Byte

Integer, Word

Longint

Real

Single

Double

Extended

. 73

,
, . 73 . ,
.
,
.
, ,
.

218

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
.

219

32

.
. , 32- Delphi Integer LongInt
4- , 8- Int64.
. 2

Byte

255

Shortint

-128

127

Word

65535

Integer (BP, FP)

-32768

32767

Integer (Delphi)

-2147483648

2147483647

Longint

-2147483648

2147483647

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

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

- }

var

N : byte;

begin
N:= 255;

{ 255 }

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

.
,
. Range checking
(. 74).
220

32

$R

$Q

. 74

Runtime Error 201.


, ,
.
,
( + ).
{$R-

- }

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

- }

var

N : byte;

begin
N:= 0;

{ 0 }

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

: 255! ,
, !
, .
221

32

, ,
. ,
32767 INTEGER
-32768. :

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

Minimum

Maximum

Maximum = Minimum 1
()

. 75

!
,
.
:
(99999) .
,
,
.
, , Longint,
,
:
{ $R- }
var

B: Byte;

S: ShortInt;

W: Word;

N: Integer;

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

,
N !
, $R+.
222

32


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

{ N }

procedure Dec (var N : longint);

{ N }

N LONGINT,
: INTEGER, WORD, BYTE,
CHAR BOOLEAN.
var

B: byte; N: integer; C: char;


. . .
Inc(B);

{ B:= B+1 }

Dec(N);

{ N:= N-1 }

C:= A;

Inc(C);

{ B}


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

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

M : 1..12;

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

223

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. , .

224

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 { }

.
225

32

if M2 > D1 then

{ }

if 'W' > 20 then

{ }

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

{ }

if Ord(W) > 20 then

{ }

-
, , , ,
.
(
). (INC)
(DEC) , Borland.
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 , :
226

32

{ $R+ }
var

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

B:= Succ(B);

{ }

B:=0;

B:= Pred(B);

{ }

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

B : byte;

{ 0 255 }

C : a..z;

{ }

. . .
C:=z;

C:= Succ(C);

{ R+ }

B:=255;

B:= Succ(B);

{ Q+ }


FOR-TO-DO
. :
, :
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);


:
CASE-OF-ELSE-END:

227

32

var

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

:
type

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

var

m : TMonth;

{ }

. . .
Case m of
Jan, Feb, Dec

: Writeln();

Mar..May

: Writeln();

Jul..Aug

: Writeln();

Sep..Nov

: Writeln();

end;

, ,
.


$R+ $Q+ .
,
.
, .

: , .
.
, ,
.
,
.
,
, .
$R+
, .
228

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 ,

.
( TMonth CASE).
) . ,

, .
, .
: -, DIV MOD. -,
LONGINT ( INTEGER),
(86400) INTEGER.

229

33

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


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

, E
-0002. : , E,
, . ,

. ,
, 0.0333333343267441.
, ,
3.33333343267441E+0003

: 3333.33343267441.
, .
,
. ,
:

230

33

9.1093829140E-0031 = 9.109382914010-31 ,
1.9889200000E+0030 = 1.98892000001030


:
.
, ,
. ,
.
.
10/3, : 3.333... ..
.
{ }
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

, ... :
,
, .


, ,
.
. . 3
.

231

33

. 3

()

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('Single

= ',

F1:23:18);

Writeln('Real

= ',

F0:23:18);

Writeln('Double

= ',

F2:23:18);

Writeln('Extended= ',

F3:23:18);

end.

1/3 ,
,
( Borland Pascal, ):
Single

0.333333343267440796

Real

0.333333333333484916

Double

0.333333333333333315

Extended=

0.333333333333333333

, Extended :
. . ,
? .

232

33

.
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 ,
. Abs(A-B)
: |A-B|.


, ,
. , .
,
. ,
. .
, Integer.
, , -
233

33

, Longint Extended.
, ,
.
.

, TYPE .
. , ,
Integer.
Type

TValue = Integer;

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

TValue = Integer;

Var

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

A, B C
Longint, .
Type

TValue = Longint;

TValue Longint.
,
.
. ,
.

234

33


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

,
. .
:
. ,
, :
Var

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


. . .
{ }
I:= B;

W:=B;

L:= W;

L:=I;

{ }
B:=I;

I:=W;

W:=L;

N ,
N (.. N mod 256 N mod 65536).


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

{ 68 }

Writeln ( Char(68) );

{ D }

, Char.
, . , .

235

33


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.
? .
.
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
), ,
. !

, .
,
, , ,
.

,
, .
,
236

33

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

{ 3 }

Writeln ( Round(3.75) );

{ 4 }

Writeln ( Round(3.25) );

{ 3 }

. 76,
.

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


,
. , ,
.
.
SizeOf.
, ,
. .
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 }

237

33

Char ()
Char

Ord()
Boolean()

Byte,
ShortInt,

Boolean

Integer,
Word,
Longint,

()

Ord()

Ord()
Trunc (), Round ()

Real,

Single, Double, Extended

. 76

SizeOf ,
, .
, ,
.
SizeOf ,
. , Free Pascal
Integer (2 4 ).
SizeOf,
, .

238

33

,
.
,
.
Extended ,
Single .
,
.
, , .
.
,
.

,
Trunc, Round.

, .
TYPE,
.
, ,
SizeOf.
.

?
) , :

(: 3.1 4; 3.9 4);


(: 3.1 3; 3.9 3).
) ,

.
) 20

0 10. :
, , Random(10000)/1000.
) 20

0 10 , . :
.
239

33

) .

: 1
. .
( )
. .
) . ,

S=DD, D .
S , D? S
( ). , S=9, D=9=3.
SQRT.
MySQRT, . ,
D0=1. , D

Di+1 = (Di + S/Di)/2
, S=9 D1=(1+9/1)/2= 5, D2=(5+9/5)/2= 3.4 ,
D
. MySQRT
0.0001.
D. : Di Di+1
.
) : , ,

. , .
, 100:5:7:500 , 100 5
, 7 500 .
,
, . :
4 .
4 .
:
.
4 .

240

34

,
, 32- .


.
:

, ;

;

.
,
,
(. 77).

IF-THEN

REPEAT-UNTIL

IF-THEN-ELSE

WHILE-DO

CASE-OF-ELSE-END

FOR-TO-DO
FOR-DOWNTO-DO

. 77

,
:

241

34

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


(Section , ).
.
. 78 .

Const

Type

Var

Function
Procedure

Begin

end.

. 78
242

34

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


,
. ,
.
, ,
( ). , ,
,
.
.
.
.
, .
. 79 ABC.

243

34

Procedure ABC ()
Const ...


( )

Type ...
Var ...

Begin
. . .
end;

. 79

, , ,
.
,
, :
;
.
,
.
, ,
.




. , ,
. , .
:
;
;
.

244

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 ( )

245

34

.
. CONST
( ).
.
, , VAR.


, ,
, .
.
.
.
, .

?
,
. ,
. ,
. ? ?
, !

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

.
, .

.

246

34

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

) Test .

, ,
:
Writeln( Test(20, 4) );

{ true }

Writeln( Test(21, 5) );

{ false }

) Division

DIV. :
Writeln( Division(20, 4) );

{ 5 }

Writeln( Division(21, 5) );

{ 4 }

: .
( ). :
1) , 2) .
) ( )

, :
: 60
2

) . -

, :
X:= GetNumber( =);

247

35

, -
! ?
...
. ,
!


.
, .
- ( ),
.

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

,
,
. ,
, , .
, . ,

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

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

35


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

B (Black)


W (White)

. 80 (B) (W)

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

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

.
, .
249

35

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

. 81 G = B + W

,
. G ( Gray )
, , :
G=B+W
,
. ,
B W, , . ,
(. 82).


G<B+W

. 82 G < B + W

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

( )
, (. 83).

250

35


G=B*W

. 83 G = B * W

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

BWW


, - .
; . 84
?
. ,
, .
:
G = B W

G=WB

G=BW

G=WB

. 84

, ,
? , ?
!
251

35

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

. 85 . ,
. :
.
:
B>W
B

. 85 (B) (W)

? ,
, ,
. :
B W , B W;
B W , B W.


.
.
. :

1 9 (. 86).
( , ).

252

35

9
2
3

. 86

. ,
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} ,
.
, :
, , .
.
,
() :
G = A + B = { 8, 7, 9, 3, 5, 2 } + { 5, 4, 6, 1, 2 } = { 8, 7, 9, 3, 5, 2, 4, 6, 1 }

253

35

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 }
. 86.

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

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

.
.
, .
254

35


.
,
.
. ,
.

?
)

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

?
- ,
.
?
: .
, ?
) , A B, ,

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


?

?

255

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 }

, ,
. , ?

.
256

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 }



,
.
,
:

257

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

(=>) ,
:
258

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).
259

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
, .

260

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.

) 20 1 50 ,

. :
Random
.
) (.
), ( F7).

Watch
. ,
21.

261

37

.
, c : .
- 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;

262

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 .
: CONST.
,
CONST VAR .
, .
Assign(F,''),
.
( ), ( ).
,
, WriteSet (
Pascal ABCNet).
. (Delphi)
FOR-IN-DO. :
for k in aSet do Write(aFile, k:4);

.
, .
?
, .
: ,
. ,
.

263

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.

,
,
. ,
:
264

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.
:

265

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 }

266

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.

, , .
.


, .
() ,
.

.

?
) .

?
)

,
.

, . ?
) , :

,
, PASCAL ACLPS;
, , ,
PASCAL PASCL.
267

38

, ... ,
? , !

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

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



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

268

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 ( ).
269

38

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


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

270

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

. 87

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

271

38

29 21 30 31 32
17 18 19 29 28
3 4 5 20 19 18
6 7 22 21 20
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;

272

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.
.
, .
.
,
. , .
? 49, 57 58.


, . ,
,
273

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. .
, 20.
1 20. 1 2 ,
, , 4, 6, 8 .
.
: 6, 9, 12, 15 18 ( ,
). ,
. : 10, 15, 20 (
). 11, .
, .
. , ,
N, 5.
.
, ,
. :

274

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
:

275

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, , .
, 35 70 ( 7, 5) ,
.
276

38

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

1 255. , , :
120 31 16 25

,
, .
, . :
.
) .

: , , :
7UpJ7rsT, PasCal701. ,
:
,
;
( );
,
;

Pa7sCaL5,

.
) , ,

277

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 , .
.
, , .
278

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.');

279

39
()
end
end
end;
Readln;
end.

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

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



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

280

39
()

. 88 () ()

, .
.
. , ?


, , : VAR,
TYPE.
, VAR:
VAR

_ : ARRAY [<MIN>..<MAX>] OF < >

ARRAY OF,
. ,
; .
, , : 1)
2) .
.

. ARRAY,
, MIN MAX,

281

39
()

. ,
.
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. ,
. ? ,
, .
282

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
( ?).

, :
TYPE

{ 30 }
TRatings = ARRAY [1..30] OF byte;

VAR

{ 30 }
Ratings : TRatings;

283

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

A, B, C : TRatings;

{ }

begin
. . .
end;

TRatings
.
, .

()
- , ,
.
, ?
: ,
. ,
, .
, ,
. , ,
, .
.
1. Names :
Names[1]:= ;
Names[2]:= ;
Names[3]:= ;

2. Ratings.
n.
...
Ratings[3]:= 12;
Ratings[4]:= 8;
n:=3;
if Ratings[n] > Ratings [n+1] then ... else ...;

, ,
. !

284

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? ,
285

39
()

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

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

, N,
. 27
, .
, ,
, , .
, $R,
:
Options Compiler Runtime Errors Range checking

($R+).
, ,
Range check error. , ,
.
($R-) .
, .
. ,
!
.

. :

286

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

,
, .

,
.
.

.
:
.

.
,
.

, .

?
) A C :
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;

.
287

40

, .
,
, , - .

-
16- ,
. ,
. ,
.
,
.
, ,
? , , .
? , ?
, ,
. , 100
.
.
. ,
,
.
Fact, .
, 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;

{ }

288

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');
ReadFromFile(F);
Randomize;

Reset(F);

Close(F);

{ }

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

Readln(S);

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

until S='';
end.

P_40_1.IN, ReadFromFile (
), Answers ().
Fact. ,
, ,
, , Fact.
, :
.
Random(Fact)+1. ,
Random(Fact) 0 Fact-1,
.



( 29). ,
. , ,
! ? , ,
, . ,
, !
289

40

P_40_2
ReadFromFile. , Fact
1 , , ,
.
, .
{ 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 { }


while Eoln(aFile) do

{ }

if Eof(aFile) then Break else Readln(aFile);


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;

290

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;

. ,
. , ,
. , :

291

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.


. . ?
292

40

, , .
,
.
.
.

.
Read (.
ReadFromFile P_40_2).

?
)

( , !).
) ,

0 255 .
) ( ) , 7 (

). , .
) ( ) 0 255

, .
, .
) ( ) ,
, .
) . 10
. , 1- 2-
, 2- 3- .. 1- .
) . 2-

1- , 3- 2- ..
.
)

, ,
( .. ) .

293

41
, !
39- , ,
.
, .


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

(. 89).
, , ? ,
.
?
,
.
, , ,
.
.
, .
. ,
294

41
, !

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

(3 4)

(2 5)

(1 6)

. 89

, ,
, . .


. :
, .
Bubble Sort.
? :
.
- 10
.
P_41_1,
. .
BubbleSort,
.
.
FOR-TO-DO, . J
295

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;

:
VAR. , ,
CONST VAR .
, .

296

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 ,
.

297

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.

298

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.

299

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.

300

41
, !


20 Length(Names[i])

,
, .

, ( CSize
4), :
:

55

54

47

43

, .


.
.
,
.

?
)

( ).
, , .
)

.
) (

).
?
) , , .

TRUE, .
.

301

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, . ,
, .
302

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;

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



. ,
,
. , .
, .
. 90.

303

42
,

4
3

5
6

. 90

, ( )
. ,
.
?
? ! . . 91
, 12 .
. 32,
() . ,
8 , 32 8- .
.
, - ,
:
(1+12)/2 = 6

304

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
. 91

305

12

42
,

, .
, 6 21, 32.
, - . , ,
, , .
, ,

(7+12)/2 = 9
40 32.
, , , , ,
. , 12
. ,
(7+8)/2 = 7
27.
32.
: 8 ,
4 . : -?
. ,
. ,
, .


,
. - .
- (. 92), ,
: L (Left),
R (Right), M (Middle).

306

42
,

:= -1
L:=1
R:=

Repeat


M:= (L+R) / 2

:=M


R:= M -1


L:= M+1

L<=R
UNTIL L > R

. 92 -

, , FindBin (Find
, Binary ), . ,
.

307

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 ().
, (
). ,
, .

308

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;

{ ! }

309

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_42_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;
Close(F);
end.

310

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 ! ,
.

311

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)
!
312

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
.

313

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.
. 93 .
, .
(
!).

. 93
314

42
,

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

?
). ?

.
)

? ? .
) ,

. ,
, :
123 .., . , . 21, . 11-22-33
35 .., . , . 5, . 33-22-11

.
)

.
) , .

,
.
. , ,
, . : ,
. : 5000?
.
. ()
.
315

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


? ,
?
.

.
,
( ). ,
. ,
.
, .

. , .
, .
, ,
( , ).
, , :
.
, , ,
. ,
, .
, , .
, .
, N-1 , . ,
, , , , ,
?

316

43
-

Left

Right

. 94

, ,
?
, , ,
. , .
, ,
FarmSort .
. ,
, ?

{ P_43_1

c }

const
CSize=10;

{ }

type
TNumbers = array [1..CSize] of Integer;

{ }

var
Arr

: TNumbers;

{ }

317

43
-
{ }
procedure FarmSort(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(' :');
FarmSort(Arr);
ShowArray(' :');
end.


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

43
-

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

43
-

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


, .
, ?
, , ?
,
, .
. !
! ,
.
, . ,
. , 1/3 2/3
. ,
( ).
: ,
.
:
:= ([L] + [(L + R)/2] + [R]) / 3;

L R
. :
.

320

43
-

,
, ,


.

. 95

?
QuickSort (Quickly , Sort ).
.

321

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;

322

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)
, ,
.
323

43
-

, .

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

.
, .

, .
,
, .
( ),
.
,
. ,
.
! , .
P_43_2 .

, !
,
? :
BubbleSort
FarmSort
QuickSort

,
,
.

. , :
, . 42- ,
324

43
-

, .
. , ?
. - ... ,

, .
, , ,
(P_43_3).
C1 C2. EXTENDED,
. ?
,
, , , .
EXTENDED.
,
.
(C1) (C2), . ,
,
.
Arr0,
Arr .

.

325

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;
{ FarmSort }
procedure FarmSort(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;

326

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;

{ }

FarmSort(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.

327

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 .
. !
,
. , ! ,
: .

328

43
-

BubbleSort

FarmSort

QuickSort

. 96 ?

, (. 96), ?
. , ,
. N
, N .
NN. ,
.
. ,
Log2N.
NLog2N. ?
, . ,
QuickSort (. 97).

NN

N Log2N
N

. 97

329

43
-

,
.
BubbleSort FarmSort
, .
QuickSort ,
.

?
) (

).
.
) QuickSort

. , Level
. , QuickSort,
, .
QuickSort:
begin
Inc(Level); Writeln(' = ', Level);

QuickSort:
Dec(Level); Writeln(' = ', Level);
end;

) QuickSort ,

Level Log2N
( CSize).
CSize.
) .

, ,
? ,
, .

330

44

STRING ,
.
. ,
, Borland Pascal (
ShortString).


. ?
. , 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 , . ?
? . 98.

255

. 98 PASCAL

PASCAL.
1- 6- , .
331

44

.
6 PASCAL. ,
, (
Length).


- .
( ) 256 , .
, .
256 ,
? , . ,
, , 20 .
, .
.
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
, .

332

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 , .

333

44

function Pos(SubS: string; S: string): Integer;

:
SubS , ( );
S , .
SubS ,
SubS S, .
S ,
. .
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:= Free Pascal forever!;
T:= Copy(S, 6, 6);

{ Pascal }

T:= Copy(S, 6, 255);

{ Pascal forever! }

,
, ( ).
334

44

(Insert)
.
? Insert.
procedure Insert(S1: string; var S2: string; Index: Integer);

:
S1 ;
S2 ;
Index .
:
S:='!';
{ 8 : }
Insert(' ', S, 8);

{ ! }

S2, S1
S2. S2 ,
.
(Delete)
: . , ,
. ? Delete .
procedure Delete(var S: string; Index, Count : Integer);

:
S ;
Index ;
Count .
.

335

44

S:= Free Pascal forever!;


Delete(S, 6, 7);

{ Free forever! }


( ).
.

. ,
. :
Writeln (Borland > Pascal); { false, B < P

Writeln (ABC > AB);

{true, ABC AB }

Writeln (ABC > abc);

{ false, A < a

Writeln (45 > 1000);

{ true, 4 > 1 }

B P,
. ,
, . ,
.
, , !
,
( ). ,
, ,
( DELPHI ).
(Upase)
Upase ,
. , ()
(). .
function UpCase(Ch: Char): Char;

, ,
, .
c:= UpCase(r);

{ R }

c:= n;
c:= UpCase( c );

{ N }

,
, .
Upase.
336

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 ( - ?).
337

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.

.
.
, , 256
255 .
.

STRING.
,
.

?
) , (

) .
)

( ). : .

338

44

) .
)

,
, . ,
, : MyCopy, MyDelete .
) . , 1-

2-, 2- 3- ..
1- . .
) . 2-

1-, 3- 2- ..
.
) .
.

.
.
,
80 ( 80).
) , , ()
. .
) , ,
(, TRUE).
, . : .
) , .
, .
)
( ).
) , ,
.
)
, :
, ..

339

45

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



. ,
, :
? ?
: , .
: , ?.
. : ,
. - . ,
. ,
. ? ,
. , . ,
. ,
.
,
.
LIFO, Last-In, First-Out, -:
. ,
. ? :
. , , ,
.
, ,
.
? ?
, , .
,
. ,
.
340

45

.
, .

.
FIFO,
First-In, First-Out , . ,
.
,
: , . :
.


.
.
,
.
, , .
, .
, .
,
, , . ,
.
, ( ),
. ,
, .
,
. , ,
, - .
: , ( ,
).

. 99
341

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.

342

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:=''; { }

343

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, .
, ,
.
344

45

GetFromQue, ,
, .
, (TRUE,
).
arg, . , , .
.
.


, , . ,
?
, , !
. 100.

4
. 100

,
, . ,
1
( ). ,
. !
.
1, ;
. ,
,
. .
, .
, ,
. : , !
, .

345

45


, ,
.
.
; ,
. , .
, ,
. ,
. , .
,
(. 101).

. 101

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

346

45

, .
(), . ,
AZ, A; ,
az, B, ,
09, C.
. ,
, .

.
. , .
: ,
.
: Push ,
Pop .
Push .
-- ,
.
Pop ,
. ,
. ,
: ,
.

P_45_2. :
Pop,
.

347

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(' :
SA:=; SB:=; SC:=;

{ }

'+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);

{ }

{ B }

348

45

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).

?
) , ,

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

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

349

46

,
,
...

?
,
, , . ,
, ,
, , !
,
.
, !
, ,
.
LongInt .
2'147483647,
. , ,
.
Extended,
104932 ! ,
! ;
Extended , . ,
( ),
, , .
? . ,
. ,
, .
! . , ,
.


.

. : , ,
?
? . 102 .

350

46

+
3

. 102

, , .
,
10 ( 0 9),
.
A B,
.
:= (A + B + ) mod 10
:= (A + B + ) div 10

, MOD
, DIV .
.
, .


,
.
: ,
0 9, 09.
, , 255 ,
.
,
P_46_1,
.

351

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) .
352

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,
(
). .
353

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;

{ }

354

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 F : text;
begin

i : integer;

{ === === }

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


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(F, BN1);

{ }

WriteBigNumber(F, BN2);

{ }

AddNumbers(BN1, BN2);
WriteBigNumber(F, BN1);

{ }

Close(F); Readln;
end.

,
?
. .

355

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 (
) . ,
356

46

, ,
, .

?
)

( 255).
) . ?

, !
) Input Output

.
, :
Assign(Input, 'Data.In'); Reset(Input);
Assign(Output, 'Data.Out'); Rewrite(Output);
Readln(S);

{ Data.In }

Writeln(S);

{ Data.Out }

Close(Input);

Close(Output);


. WriteBigNumber, ,
.

)

. ,
,
.
, ,
, .
.
, ,
, , (3+2+1).
, ,
. ,
, ,
.
) ,
(. ).

,
( ).
.
357

47

,
, .


? ,
.
!
, !
?
, , .
(,
). ? !
.
, .
1, 2, 3 .
0. , , ,
.
, .
,
15-16 !
,
: ? ,
, !.
, .


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

358

47

Twelve -

12

111111111111

1100

0h

$0

. 103 12

, , .
: , ,
. , ,
. ,
!
.
Writeln , , ,
. ,
Writeln ,
. , :
, .
,
. Readln, .
,
. ,
(, ). , ,
.

359

47


:
, , . , 2048
.
2048 = 2 1000 + 0 100 + 4 10 + 8 1
.
2048 = 2 103 + 0 102 + 4 101 + 8 100
, ,
, .
:
. ? ?
, .
, ,
, .
_ := MOD 10

.
, ,
.
_ := DIV 10

, . 104.

360

47

N mod 10

N div 10

. 104

, .
,
. .
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.
361

47

010.
, ,
. 105.

0

N = 0

2
10

+2

2
+0
10
2

+4

0
10

N=2048

+8

4
10

. 105

, 2048 :
N = 0 -
N = 0 10 + 2 = 2
N = 2 10 + 0 = 20
N = 20 10 + 4 = 204
N = 204 10 + 8 = 2048

, .

362

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
(. 106).

3

12 = 1 8 + 1 4 + 0 2 + 0 1

. 106 12
363

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
. 107 .
364

47

1111.1010.0101 2

15

10

. 107

,
, .
: ,
H ( Hexadecimal, Hex ).
, FA5 :

0FA5H

0FA5h

. ,
0x (0xFA5), $
($FA5). ,
, , (
), :
12

0x0C

$0C

(byte)

4005

0x0FA5

$0FA5

(word)

4005

0x00000FA5

$00000FA5

(longint)

?
.
.

. , - ,
.
.
365

47

. 11

0000

16-
0

1000

16-
8

0001

1001

0010

10

1010

0011

11

1011

0100

12

1100

0101

13

1101

0110

14

1110

0111

15

1111


, :
, . ?
!
, .
2048 = 2 103 + 0 102 + 4 101 + 8 100

- ;

12 = 11002 = 1 23 + 1 22 + 0 21 + 0 10

- ;

4000 = $FA0 = F 162 + A 161 + 0 160

- .

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


, ,
, .
, .
,
MOD 2, DIV 2.
MOD 16 DIV 16.
: N-
366

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];

{ }

S:= c + S;

{ }

until aNumber=0;
ConvertFromNumber:= S; { ! }
end;
var B, N : integer;

{ B , 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.


, , .
367

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 .
368

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

, . ,
.
( ). ,
, ( 001 999),
N ( N ).
369

47

) . ,

45 . :
, .
?
) :

, , .
?
) : 1) , 2)

, 3) .
.
) , (

) , : 123, 702.
) .

, 3- 3-. :
123 411. , .
) 1, 2, 5,

10 25 . ,
, .
, 33 : 25 + 5 + 2 + 1.
)

. , 405
343035. .
.
)

,
: ,
( 44).
) , 1000, ,
. : 24, 36, 184, 612.
.

370

48

,
, .


,
. 8, 16, 32 64 ,
1, 2, 4 8 .
-.
? , (. 108).
, , ,
, .. , 8-
Byte, 16- Word, 32-
Longint.
, , ,
. , ,
.
, .
,
. .

, ..

. 108

371

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_47_1
ConvertFromNumber. ,
.
, .
ConvertTo2,
P_48_1.

372

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);
until A=0;
end.

:
, ,
. ,
, :
373

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,
.
374

48


,
. :
(SHL) (SHR).
(. 109)
, ,
, :
N:= 3;

{ 3 =

00000011 }

Writeln (N shl 1);

{ 6 =

00000110 }

Writeln (N shl 2);

{ 12 = 00001100 }

. 109

(. 110)
. ,
.
N:= 3;

{ 3 = 00000011 }

Writeln (N shr 1);

{ 1 = 00000001 }

Writeln (N shr 2);

{ 0 = 00000000 }

. 110

,
. TestBit, :
ARG , , BIT
375

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).
) ,

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

. 111

.
. :
,
.

376

49

, .
.


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

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


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

, ! ,
,
377

49

. . 112,
D,
A, C E, , B, I F.
2

1
17

H
16

14

3
18

28

15

29

32

27

13

20

31

19

A
21

26

30

12

F
23
24

22
7

11
25
10

- (D)
- (A, C, E)
- (B, I, F)
. 112

, , ?
. ,
,
, . ,
, . ,

, .

378

49

, ! , .
, . ,
. 38-
-. , ,
.
, . , .
TStates.
type

TBoundSet = set of 1..255;

{ }

TStates = array ['A'..'Z'] of TBoundSet; { }


var

States : TStates;

{ - }

, ?
. ,
, .
B, X,
States .
var

B : TBoundSet;

{ }

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, .
379

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
aSet:= [];
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

{--- ---}

{ }
Assign(FileIn, 'P_38_3.in'); Reset(FileIn);
{ }
Names:=[ ]; { }
C:= 'A';

{ }

380

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.

381

49

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

-
?
, ,
. ,
?
:
( ),
(. 113).

. 113

, , ,
.
, , ,
. . 114,
F.

382

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

. 114 ,
F

, .
25 80 .
20 40 .
20- 21- ,
10- 11- .
, :
.
, ? , ,
.
, .
? 800 (20 40 ).
, , ? ,
(Desk) .
type

TDesk = array [1..800] of Boolean;

, 40
, 40 , . ,
?
: TLine
40 .

383

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[3, 5]

, ,
.
, , .
, ,
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:

384

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,
('0'), TRUE ('+'),
.

385

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;

386

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;

387

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+';

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

, ,
, .
.
:
, .

388

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..1000] }

BS[N]:= true;

{ S:= S + [N] }

BS[N]:= false;

{ S:= S - [N] }

if BS[N] then

{ if N in S then - }

1
1000.
) . ,

.
. CX CY,
, .
.
. ,
(, , ).
.

389

50
()
!
, .
: ,
, . , ! ,
, , , .
: , ,
. , ,
, ? ?
, 41.
.
: , .
( P_41_3).
(
, , ),
.
, !
,
, .
, .

!

.
, - RECORD. , ?
. , ,
,
: , , . .
. ,
, .
RECORD-END
, .
.
, Team .
, .

390

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,
( ) . .
: .
.
391

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- , i- ( TTeam)

Champ[i].mAces

i-

Champ[i].mName

i-

P_50_1 .

392

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.

393

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 . ,
.

394

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.

.
, ? !
, .
395

50
()

,
.
RECORD-END,
, .
,
.
,
.

?
) P_50_2 , .
) .
, , ?
)

. ,
.
) :

, .
, : 1) , 2)
3) .
) . 28 ,
0 6. : 0:0, 1:5, 6:6.
, .
.
. .
) . 36 : ,

. 6
14. , , .
,
. .
11 14 : , , , .

396

51

, .
, , ,
! .


,
. , .
, ,
. 0, 1
. , ,
, .
, ,
. ?
,
.
; ,
. ,
, .
. ,
, . 115.
.
,
, ,
. .
, . ?
, .
, .
, ,
. :
, ,
, .

397

51


()

. 115


. 115,
.
(Section ). ,
, .
,
. ,
:
( ) ,
, ;
, ,
;
,
.
. .
var

B : Boolean;

C : char;

I : integer;

S : string;


, N ,
. 116.

398

51

, N

N+1

N+2

N+3

N+4

N+4+255

. 116


. ,
256 .
;
. N
( ),
.

,
.
, !
(-
POINTER). , .
, , ,
.
var

P : ^integer;

{ }

N : integer

{ }

P:= @N

{ N }

P^:= 125;

{ }

Writeln(N);

{ 125 }

begin

end.

P.
^, ,
. P
INTEGER.

399

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,
-.

400

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 }

, ,
(. 117).

401

51

NIL
( )
1

. 117

. 117, ,
. , ,
NIL.


, ,
.
. :
, .
.
if p1=p2 then ...
if p1<>p2 then ...
if p3=nil then ...

NIL , . NIL ,
!
NIL,
Assigned. ,
. .

402

51

p1 := @X;

p3 := nil;

Writeln (Assigned(p1));

{ true }

Writeln (Assigned(p3));

{ false }

Assigned FALSE, NIL.


,
. ,
. ^,
:
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.

,
( ),
, :

403

51

type

PInt = ^integer;

{ }

var

P : pointer;

N : integer;

...
P:= @N;
Writeln( PInt(P)^ );

{ N }


, ,
.
{ 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

,
, . ,
: , , .
404

51

P_51_2 ,
, ?
{ 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

. ,
32-
4 ( , ,
).
,
.
405

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.

406

52


, .
...
?



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

!
51- ,
. ,
. (- Heap).
,
.
? , !
. ,
. , .
.
,
. ,
New Dispose .

407

52


, New (
).
. ,
. .
:
var

York : ^Integer;

{ }

begin
New(York);

{ , York }

York^:=123;
Writeln(York^);

{ 123 }

end.

York.
New(York) 2 ( ),
York.
, .
:
( 2 )? ,
.


,
. ,
, , .
Dispose
. , ,
. :
var

ps : ^string;

{ }

New(ps);

{ 256 }

begin
ps^:=Hello !;
Writeln(ps^);

{ Hello ! }

Dispose(ps);

{ 256 }

end.

256 ,
. .
408

52

, , .
, .
New,
.
, Dispose,
.
.
,
. (
, ) ,
, , .
.

,
,
, . .

var

ps : ^string;

begin
ps^:=Hello !; { }
end.

, ,

.

var

ps : ^string;

begin
ps := nil;
ps^:=Hello !; { }
end.

:
.

409

52

( )
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.

. ,
.
.
! , !

. ,
,
. ,
. ,
:
var

p1, p2 : ^string;

begin
New(p1);
p2 := p1;

New(p2);

{ }

{ }

Dispose(p1); { ... }
Dispose(p2); { ... ! }
end.

, p2
. ,
410

52

! ,
.
,
, .
!

.

, ,
.

, .
,
.
New,
.
,
Dispose.
;
, .

?
) ,

.
.
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.

411

52

) .
var

p1, p2 : ^integer;

begin
p1 := 10;
p2^:= 20;
New(p1);
p2:= p1;
p1^:= '!';
Dispose(p1);
Dispose(p2);
end.


) .

,
, . , 10 ,
: 3, 6, 5, 6, 3, 6, 5 ..
, .
: .
, ,
.
,
.
.
. ,
() 1 N .
N 255.
) ,

, .
,
. :
1,5..255
0..200,210..255
0..255
2,5,7,10..20,30..40

412

53

.
, ,
.
. 118, .

^Char

^LongInt

^String

Char
Longint
String

. 118

, ,
. ,
.
.



. ,
, .
, , .
.

413

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 , . ?
.
:
, . . 119 .
PRec

PRec

TRec

TRec
TRec

. 119

414

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;

415

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.

416

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.
FillChar(DataBase, SizeOf(DataBase), 0);

, ?
FillChar,
.
NIL.
, ,
P_53_1.
417

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;
{ FarmSort }
procedure FarmSort(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;

418

53

var

F : text;

begin

{--- ---}

FillChar(DataBase, SizeOf(DataBase), 0);


Assign(F,'P_53_1.in');
Count:= ReadData(F);

{ }

Writeln(' : ');
ExpoDataBase;

Readln;

FarmSort(DataBase, Count); { }
Writeln(' : ');
ExpoDataBase;

Readln;

end.

.
( 43).
, .
-, , . 49-
( ?),
. .
, . ,
, .
.
, .
- :
, . ?
. ,
.
,
, .
, .
Right
, .

,
.
NIL.
.
,
, , .
.
419

53

?
) TRec .
( ).

.
)

. ,
.

) ( 54-).

,
. - .
.
256, (0...255). ,
, .
,
- , .
()
, .
. ,
0 255
.
.
, - ()
.
. (
),
: -.
, , ,
( , ).
, (
).

420

54

,
. , ? ,
, ? ?
. ,
. ,
, , .
.


.
: , , ,
.
? ,
. 120.


( )

NIL

. 120

( ),

. ,
. NIL, ,
, , ,
, .
. ,
( ).
, - List.
421

54

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


.
: .
type
PRec = ^TRec;

{ , TRec ! }

TRec = record

{ }

mNumber : integer;

{ }

mFam

: string[31];

{ }

mNext

: PRec;

{ }

end;

TRec , mNumber mFam,


mNext (Next
).
, ,
! ,
. mNext.
PRec TRec,
. TRec,
! , ,
?
, :
, .
. ,
.


. :

, .
P_54_1, .

422

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.

.
AddToList :
P^ .
423

54

, P ,
. , ,
, .
P^ List
mNext , P
. .
P^.mNext:= List;

{ }

List:= P;

{ }

, , !
.
P , .
.
. 121 . 122 .
, , List
NIL, .

P^.mNext:= List;

NIL P^.mNext (
).
List

P
_1

NIL

1
_1
???

. 121

424

54

List:= P;

List.
, ,
(. 122). P ,
,
List.
List

_1

_1

_1
NIL

. 122


.
List mNext .
.
. ,
.

List

2
_2

_1

1
_2
_1

???

NIL

. 123

425

54

List

_2

_2

_1

_2

NIL

_1

. 124


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

,
. ,
.

426

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;

427

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.

.
( -!).
, .


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

, , . ,
.
,
. .
428

54

. ,
.
: ,
. ,
.
( . 125 . 126
). , 20, 30 40,
35. p^
, .
q. q ( ),
(. 125).
p^.mNext:=q^.mNext;

{ }

q^.mNext:=p;

{ }

List

_20

P
_35

_30

2
35

20

???

_30
30

_40

40
NIL

. 125 35

. 126.

429

54

List

_20

_35

_30

35

20

_40

_30
30

40

_35

NIL

. 126 35

. ,
, .
List:= p;

{ , }

,
. .
p^.mNext:=List;

{ }

List:=p;

{ - }

,
q. :
q ,
, , q
. , , .
q:= List;

{ , List<>nil }

while Assigned(q^.mNext) and (q^.mNext^.mNumber < aNumber)


do q:=q^.mNext;

q^.mNext^.mNumber
q .
P_54_3, .

430

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;

431

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;

432

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), ', ');
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.

,
.
,
, .
433

54

,
.

.
(
). ,
.
.

?
) ;

, .
) - .
) . ?
) . :

( ).


) 53- .


, ,
, .
, ,
.

,
53-.
: .
:
().
.
, () .

434

55
, ,
,
.


,
.
,
. ?
, ,
150 , 10000 .
150 / 10000 = 0,015 1,5%.
, ,
, .
, !
,

.


, .
, .
,
: .
, ? !
, ,
- , ,
. ,
, .
, , .
Begin, NIL, P1, q2, Words_Count, _1_
,
, .


,
. ,

435

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, , ,
.
.
, .
1. .
2. ,
, , ,
.
3. .
4. .
5. , ,
, .
436

55
, ,

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;

437

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;

438

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_55_1.OUT');

PrintList(F);

{ }

end.

439

55
, ,

,
. .
( ).
ADDLINE

ADDTOSORTLIST

ADDWORD

AND

APPTYPE

ASSIGN

ASSIGNED

AWORD

10

BEGIN

14

CLETTER

?
) :

;
.
.
) ,


.
) ,

: , : end deen, 121 221.



( )
, , :
1 2 2
d e n 2

: ,
. , ,
.

440

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).
.
,
. , .
?
441

56
,

:
, . , ,
, (. 127).

_3

Stack

_2

_3

_1

_1

_2

NIL

. 127

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

PRec = ^TRec;

{ }

TRec = record

{ }

mStr

: string;

mNext : PRec;

{ }
{ }

end;

, , , :
PUSH, POP.
.
procedure Push(const arg : string);

, .
. ,
: , -.
.

442

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;

443

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- .
, .
. ,
, , .
,
. ? :
(. 128).

444

56
,

Queue

_3

_2

_3

_1
NIL

_1

_2

. 128

, . .
.
, . , ,
:
, .

.
. NIL,
(. 129).
.
Queue

P2


P1

_3

_3
_2

_2

_1
NIL

NIL

. 129

445

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.

446

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;

447

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.

448

{ }

56
,

:
+
+
+

, 8 , - .


, .
, ,
,
.
,
Dispose.

?
) MemAvail ( Memory

, Available ).
.
Push Pop :
Writeln(Push :, MemAvail);

Writeln(Pop :, MemAvail);

.
) 45 ,

. ,
. ?

449

57

! 49-
.
.
.
.
. 130 , .
, , .

H
B
C

I
A

D
F
E

. 130

, 38- ,
.

450

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

:
, ,
. ,
, ? ,
.
, - . ,
.
(. 131).

H
B
I

C
A
F
D
E
. 131

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

57


, .
.
.
, .
Node , Link .
(. 132),
. , .
. ,
, : .

. 132

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

452

57


. ,
. ,
.
, .
?

. 133

, ?
, .
,
. - .
.
, . ,
, . ?
, . ,
.
. , .
? (. 131).
.
!
.
. ,
. . ,
mNext
. ,
. 134.

453

57

H
mLink

mNode

mNode

mNode

mNext

mNext

mNext

NIL


G
mLink
mNext

I
mLink
mNext

B
mLink
mNext

. 134 H

,
, .
, , mNext,
.
.
454

57

,
. mLink.
, H.
, mNext,
mNext .
mNode, . ,
, ,
. . 135 , . 134.

H
B
I

. 135 , . 134

, H,
. , G
H, .
G H (. 136).

. 136 () ()

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

.
455

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.
.

456

57

, .
, , ?
,
( ). ,
( P).
.
. , ( q),
, P q.
: P q. ,
, , ,
. ,
B C, B C.
- (. 137).
, ,
:
;
;
.
.
function GetPtr(aName : char): PNode;

.
, , NIL.
MakeNode ,
.
function MakeNode(aName : Char): PNode;

, , Link
.
procedure Link(p1, p2 : PNode);

, .

457

57

P ?

q ?

q
P q

. 137

, .
procedure ExpoData(var F: Text);

,
.
P_57_1.

458

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;

459

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;

460

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

, , ?
, .
461

57

. !
, ,
.
,
. !

, .

.
.
,
.

?
) - (. 130)

. ,
. , .
)

. .
)

. ?
.
) , .
, :

, -
. .
?

462

58
!
, ,
. , ,
E H, .
, F G (. 138). ,
, , ,
.

H
B
I

C
A
F
D
E

E H
E H

. 138 E H

? !
- .
, 49- ?
. .


, ?
! , ,
?
463

58
!

, . ,
, . ,
.
. 139 (
). .
() : 1) , 2) ,
3) , .
, ,
.
? E.
. ,
E .

H
B
I

C
A
F
D
E

. 139 E

:
?
. , E ,
D F,
. 140. , ,
.

464

58
!

H
B
I

C
A
F
D
E

: D, F

. 140

, , .
,
.
, E , D F
( D, F
). . ,
D A C.
- .
( D F)
, . 141 . 142.
.

465

58
!

H
B
I

C
A
F
D
E

: F, A, C

. 141 D

H
B
I

C
A
F
D
E

: A, C, G

. 142 F

466

58
!

, , ? ,
, ,
, . ,
, ,
.
, , , ?.
!
, E,
, (. 143).

H
B
I

C
A
F
D
E

. 143

,
. ,
. , D F
E, . G
F, H G.
.
, .
,
. ,
,
( , ).
, .
?
467

58
!

, .
mPrev . , F D E.

: .
, 49-
. ,
, ?
.
,
, .
, , . 144.

H
B
I

C
A

3
2

F
D

. 144

.
, ,
, .
,
. . ,
,
.


, ? -,
mPrev
. -, ,
468

58
!

mDist .
: , . mColor ,
: White, Gray, Black (
32).
:
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 .
, .

469

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;

470

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;

471

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;

472

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.

473

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 , .

(. 145).

H
3

B
G

C
A

F
D
E
0
. 145

474

58
!

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

-
.
, :
.
.
,
.
, , , .
NIL, .
MakePath .
function MakePath(arg : PNode): string;

, ,
. A B C.
.
, : .
,
, MakePath.
, ,
.
, :
;
;
;
;
.
475

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;

476

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;

477

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

! ! !
? ! ,
!

. ( ),
, .
,
[9] [17] .


. ,
.
,
.
, .

?
) , 20 ,


P_58_2.
) , .
.
? -.
478

58
!

) mDist TLink.
TLink = record

{ }

mLink : PNode;

{ }

mDist : integer;

{ }

mNext : PLink;

{ }

end;

,
.
)

,
( ).
A C 20 E 40

, , .
. , A C 20 ,
A E 40 . .
)
. : ,
( ),
mDist. ,
, ,
. , .
) , ,

, .
( ).
?
)


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

(. ).
) .

479

59

59

, ?
, , .


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

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

480

59

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

, .
.
.
, , ,
.
. ,
. IDE ,
, .
, -,
. ,
.


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

481

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.pas .
.
.
,
, , , P_59_1.
{ P_59_1 }
var F : text;
begin

S : string;

{--- ---}

{ . . . }
end.

(Primary), ,
P_59_1 . ?
, . .
, MyLibr.
,
USES. ,
, USES (

482

59

). MyLibr,
.
{ P_59_1 }
uses

MyLibr;

var F : text;
begin

{ }
S : string;

{--- ---}

{ . . . }
end.

, USES ,
. ,
, MyLibr. ,
MyLibr.
F9. ,
.
MyLibr.
, . , .
,
(
).
unit MyLibr;

{ }

interface

{ }

{. . .}
{- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -}
implementation

{ }

{. . .}
end.

END . ,
, .
UNIT (),
. UNIT ,
. , PAS.
, 63- ,
. , MyLibr.

:
INTERFACE
()

IMPLEMENTATION () .
: .
. , !
483

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. , .

484

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
, , .
.
.
,
.
, ,
. ,
, ,
. . 146 :
, .

485

59

. 146 P_59_1


.
Ctrl+F9,
, .
. Ctrl+F9
, : Cannot run a unit
. , ,
. ,
.
, IDE ,
, P_59_1.
Compile Primary file (. 147).
, .
MyLibr , , .
?
, Compile Clear Primary file.

486

59

. 147


,
.
, Stack
:
Stack:= nil;

{ }

- ,
. ,
MyLibr, .
.
BEGIN,
END.
, .
:
unit MyLibr;
{ . . . }
begin

{ }

Stack:= nil;

{ }

end.

? ,
P_59_1. ,
.
.
, ,
USES ( ).
.
, .
487

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;

488

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.

, ,
?

489

59


,
.

, . . 148 ,
. , ,
: , , ,
. . ,
, ,
. ,
,
. , ,
, .


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

490

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.

. 148

, , USES.
SYSTEM.
, . SYSTEM
USES .
491

59

,
SYSTEM, .
, :
System.Writeln(F);

{ }

MyModule.Writeln(S);

{ }

,
USES (. 148).

. , :
, USES
, .
. , .


, IDE
.


( PAS)


( TPU)

F9, Alt+F9

F9

F9


( PAS)

EXE-

F9
(F9 Alt+F9)
(F9)


( TPU)

. 149


, ,
492

59

. , Borland Pascal
TPU ( Turbo Pascal Unit). Free Pascal
O PPU.
, . .

Alt+F9, Compile Compile.
, ,
.
(. 150).

. 150

, .
. F9
( Compile Make)
USES , .
, (PAS)
.
,
. ,
.
EXE-.


, IDE,
, .
,
.
:

493

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 (. 151).

. 151

,
C:\BP, C:\BP\UNITS.

(DLL)

. ,
, . -
,
494

59


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


: ,
.

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

.

?
) P_58_1 .
?
?


) . (. 57 58)

. ,

.
? .
, ?
. ( )
, ?
. : P_58_1
Expand.

495

60

,
!



, INCLUDE-.
,
.
:
. $I,
. ,
. $I ,
, .
,
.
. ,
HELLO.INC, .
Writeln(!);

HELLO.PAS .
begin {--- HELLO.PAS ---}
{$I Hello}
end.

HELLO.PAS .
$I ,
INC . , INCLUDE-
, ,
.
,
. , ,
.
,
. .


Options Compiler.
496

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 .
,
.
, .
.

497

60

{ $define Test }
{ $define Print }

.
, !
, .
:
!
, ,
.
{ $ifdef ABC }
{ , ABC }
{ $else }
{ , ABC }
{ $endif }

$IFDEF , -
$DEFINE . ,
, $ELSE , .
, $ELSE, .
, .
{ $ifdef ABC }
{ , ABC }
{ $endif }

, $DEFINE $IFDEF-$ELSE-$ENDIF
.
. , ,
,
. , ,
.
, -.
.
.

498

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 }

,
.

499

60

(INCLUDE) ,
$I .
,
.

. ,
.

?
)

( 31), .
.

) ,
, .
, .
, ( 24).
!
. ,
? :
BEGIN END .
) .

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

10, 8, 7,
5. , .
.
, 5 .
( ).

500

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.

? , ,
? (. 152).

. 152 MyApp

IDE? , ?
. - ,
501

61
()

. Exit ,
Alt+X. , ,
! ,
. Turbo Vision,
IDE Borland Pascal.


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

. , ,
( ).


, , :
;
;
.
.

502

61
()

. ,
Borland Pascal.

.
:
. ,
. ,
, .

, ,
RECORD OBJECT. Delphi
Free Pascal CLASS. ,
, .
type

TPerson = object
mBearing : integer;

{ }

mName

: string;

{ }

mFam

: string;

{ }

end;

TPerson (),
.
Report. !
:
type

TPerson = object
mBearing : integer;

{ }

mName

: string;

{ }

mFam

: string;

{ }

procedure Report;

{ }

end;

, ,
. , , .
, , ,
. ( ),
:
, , .
Report :
503

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
.
504

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.

, . , ,
:
. , .
505

61
()


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

, .
, , . : ,
, , . :
, , , ,
: .
-, . ,
.
,
() .
: .
:
type

= object
procedure

; virtual;

procedure

; virtual;

end;

VIRTUAL,
.
, .
. , VIRTUAL
,
.
, -.
506

61
()

,
, , .
type

= object ()
procedure

; virtual;

procedure

; virtual;

procedure

_;

procedure

_;

procedure

_;

end;

,
OBJECT.
, ,
.
, .
, .
.
, . 153.

. 153


,
. TPerson ()
: (TMilitary)
(TCivil), . 154.

. Init Report ,
507

61
()

.
, .

TPerson

TMilitary

TCivil

. 154 -

, ?
.
TMilitary mRank (Rank ). ,
.
Init aRank,
TMilitary .
constructor Init(aBearing: integer; const aName, aFam, aRank : string);

, ,
, . , .
, VIRTUAL? ,
.
Report. ,
, , ,
. ,
TMilitary, TPerson. ,
:
. , TPerson TMilitary
.

508

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,
.

509

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.
.

510

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 ,
.

511

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- .
. ,
TPerson :
type

PPerson = ^TPerson;

, ,
.

512

61
()
var

P : PPerson;

{ }

begin
New(P);

{ }

P^.Init(1985, '', '');

{ }

,
.
New, . New
New, .
: -
, . ,
TPerson .
P:= New(PPerson, Init(1985, '', ''));

, - PPerson,
TPerson!
. Delphi Free Pascal
, :
var

P : TPerson;

{ ! }

. . .
P:= TPerson.Init(1985, '', ''); { }

, Delphi ,
TPerson .
New, ,
.

, ,
. , .
var

P1 : PPerson;

{ }

P2 : PMilitary;

{ }

P3 : PCivil;

{ }

P1 , P2 P3 .
,
, ,
.

513

61
()
P1:= P2;
P1:= P3;

, ? !
,
. ,
. , P1
: TPerson,
, Report.
Report
, 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;


. ,
!
514

61
()

P_61_3, ,
.
{ 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;

515

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.
. ,
, - ,
516

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? .
, , . ,
.
,
. , , .
Turbo Vision.
517

61
()

,
.

-
.
,
, .
-

: ,
.
, ,
.

. .
.

?
)

( ).
TPerson

TMilitary

TCivil

,
, Report.
.

518

61
()

) 256,

. , TBigSet,
65536 ( Word).
.
type
TSetArray = array [0..4096] of word;

{ 65536 (4096*16) }

PSetArray = ^ TSetArray;

{ - }

TBigSet = object
mArray : PSetArray;

{ }

Constructor Init; { mArray )


Destructor Done;

{ , }

procedure ClearAll; { }
procedure SetAll; { }
procedure Insert(N); { N }
procedure Delete(N); { N }
function Member(N):Boolean; { N }
function IsEmpty:Boolean; { }
procedure Union(BS: TBigSet); { }
procedure InterSect(BS: TBigSet); { }
procedure Load(var F: text); { }
procedure Save(var F: text); { }
end;

48, 49- ( 49). ,


N
mArray^.
mArray^[N div 16]:= mArray^[N div 16] or (1 shl (N mod 16))
mArray^[N div 16]:= mArray^[N div 16] and not (1 shl (N mod 16))

Union(BS:TBigSet)
:
for I:=0 to 4095 do mArray^[ I ]:= mArray1^[ I ] or BS.mArray^[ I ]

.
38.

519

62
!
, . , ,
, ,
.


? .
, . ?
, ? .


. ,
, ,
Delphi .
, . :
, ,
.
!
? .
?
, 70-
.
, .
,
-. ,
, , ,

.
. ?
.
, , ,
!

.

. , ,
, .
Ada Modula ,
(, , ). ,
520

62
!

, C/C++ .
, ,
- Java C#.
. , WEB, PHP, Perl, JavaScript, Pyton WEB-
( !).

(Assembler ). ,
, ,
. ? ,
: , , .
,
!
, , .
!
,
: . .
, .
, , , !

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

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

62
!


, ,
.
. ,
,
.

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

.

,
.
, .
, .

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

. , .
- ... !
.
,
.
.
, , , .
. ,
, :
522

62
!

C ;
T ;
a ;
m .
,
.
. , ,
( , ),
- .


.
? .
?
. ,
. ,
.

, !
,
.
.
.
, ? ,
.

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

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://g6prog.narod.ru


( )

http://www.informatics.ru

http://contest.ur.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,
, Windows, , .
:
IDE Borland Pascal ;
IDE ;
CRT;
;
;
IDE;
IDE;
;
Turbo Pascal School Pak.
,
Windows.
IDE, .

IDE Borland Pascal,


IDE Borland Pascal
. 90-
Windows 3.1 .
Borland, ,
Windows, Delphi.
Borland MS-DOS: , ,
,
Intel 80x86. , !
Windows 3.1 , MS-DOS !
, IDE,
7.1. .
, 07:00
07:01. 7.0, IDE 7.1
.
, Pentium.
CRT,
529


IDE Borland Pascal

:
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



, :
1.
2.
3.
4.
5.

;
IDE 7.0;
IDE 7.1;
;
.


.
.
,
D:\Distrib\Langs\Bpascal.700, .
7.0
INSTALL.EXE,
.
. Enter,
(. 155).

530


IDE Borland Pascal

. 155

,
( D). , , Enter
(. 156).

. 156 ,

. ,
. , Enter
(. 157).

531


IDE Borland Pascal

. 157 ( Borland Pascal)


, Start Installation .
,
Enter, Esc. ,
.
Borland Pascal Directory ,
IDE. D:\BP,
IDE C:\Lang\BP. ,
Enter, Enter (. 157).
Lang BP .
, Program Manager Group Enter,
Windows ( Dont Create).
Host Platforms Target Platforms
: ,
. ?
IDE, Borland:
80x86,
Windows 3.1. IDE
TURBO.EXE, BP.EXE BPW.EXE .
IDE BP.EXE. , ?
, Host Platforms Target Platforms,
Install BP.EXE Dont Install (. 158).

532


IDE Borland Pascal

. 158 IDE

, , .
(. 159).

. 159

Start Installation Enter.


(. 160)
IDE.

533


IDE Borland Pascal

. 160 Borland Pascal

. 14.
. 14 - Borland Pascal

BGI

MS-DOS

BIN

IDE Borland Pascal,


DOC

EXAMPLES

SOURCE

Turbo Vision

UNITS

534


IDE Borland Pascal

BIN, .
IDE

BP.EXE

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 (. 160).
.
, ,
BP7BIN.ZIP BP7ETC.ZIP
IDE. ,
7.0
7.1. ,
, 07:01.

T7TPLFIX.EXE
BIN, TURBO.TPL TPP.TPL.
-, .
P,
535


IDE Borland Pascal

Q. 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.
, Windows
. , .
, ,
. , .
. BIN
BP.EXE. ALT ,
BP.EXE , , !
, ,
Pascal: (
F2), , Enter.
.
,
(. 161).

537


IDE Borland Pascal

. 161 Windows XP

,
. ;
(
). .
, IDE,
. OK.

IDE
IDE BIN
BP.TP BP.DSK IDE.
.
, . ? .
, (. 162).

538


IDE Borland Pascal

. 162 IDE Borland Pascal

IDE Borland Pascal. ,


IDE, Enter OK.
IDE,
. ,
.
.
Alt+Enter.
,
(. 161).
IDE.
Windows, (. 163).

. 163 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 (. 164). , F10.

. 164 Options Environment Preferences

Preferences ()
. 165, OK.

540


IDE Borland Pascal

. 165

, Options Save as (. 166).

. 166 Options Save as

Save Options As (. 167)


BP.TP OK. IDE
,
IDE.

541


IDE Borland Pascal

. 167

, .
, C:\User\Pascal. -
,
Files .
, C:\User\Pascal\BP.TP.



Windows XP .
,
. .
: (
!), . :
! , !
Privet! Hello!, .
, .
.

, ( Windows
XP).
1) C:\Windows\System32 (
C:\Windows) Autoexec.nt,
.
542


IDE Borland Pascal
LH %SystemRoot%\system32\kb16.com ru

.
2) Windows:
Regedit
3) (. 168):
HKEY_LOCAL_MACHINE SYSTEM CurrentControlSet Control
Keyboard Layout DosKeybCodes

3
4

5
6

. 168 -

4) 00000409
. us ru (
). . MS-DOS
Ctrl+Shift.

(
Windows Vista).
543

Windows XP


IDE Borland Pascal

RK.COM
RK-866.COM, RNBOVDD.DLL.
.
Windows XP ,
.
C:\Windows\System32.
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,
. ,
MS-DOS Ctrl+Shift.
, ,
Windows Vista.
, .
- , ,
D:\Lang\BP\Rus. RK.COM ( RK-866.COM),
C:\Windows\System32:
CONFIG.NT AUTOEXEC.NT.
AUTOEXEC.NT
LH d:\Apps\Lang\BP\Rus\Rk.com /R5

LH d:\Apps\Lang\BP\Rus\Rk-866.com /R5

IDE :
.
(. 169).
544


IDE Borland Pascal

. 169


CONFIG.NT AUTOEXEC.NT.

. 170 MS-DOS

, , ,
(. 170), :
D:\Lang\BP\Rus\Config.nt
D:\Lang\BP\Rus\Autoexec.nt

OK . ,
. MS-DOS
, .
. IDE Windows XP
(. 171).
545


IDE Borland Pascal

. 171

, .

Turbo Pascal School Pak


, IDE .
, Turbo Pascal
School Pak, .
? :
IDE Borland Pascal;
;
;
Windows.
Turbo Pascal School Pak
DOSBox ( ) MS-DOS.
, Norton Commander.
DOSBox:
,
Alt+F11.

546


Delphi
, , Delphi
. ,
.


Borland Delphi
Project1, .
.
1) File New Other (. 172).

File New Other

. 172 File New Other

2) New,
Console Application, OK (. 173).

547


Delphi

New

Console
Application

. 173

.
program Project1;
{$APPTYPE CONSOLE}
uses

SysUtils;

begin
{ TODO User Console Main : Insert code here }
end.

Project1, CONSOLE,
,
USES. , BEGIN END,
, ,
.



:
1) Project Options (. 174).

548


Delphi

Project Options

. 174 Project Options

2) Compiler
, . 175.
Borland Pascal. OK
Default, .

549


Delphi

Compiler

. 175 , Compiler

3) File Save
File Save Project As (. 176)

Save

Save Project As

. 176

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.

.

, :

551


Delphi
SetConsoleCP(1251);
SetConsoleOutputCP(1251);

Windows,
Uses. .
program Rus;
{$APPTYPE CONSOLE}
uses SysUtils, Windows;
begin
{
CP1251
(Win-1251). ,

:
-> "" -> Lucida Console.
}
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
Writeln(', ! (Lucida Console CP1251)');
Readln;
end.

, (. 177).

. 177 -

,
.

(. 178).
552


Delphi

. 178 -

, Lucida
Console (. 179 ). ,
(. 179 ).

. 179 - () ()

(. 180).

. 180 -

553


IDE Pascal ABCNet
Pascal ABCNet
. ,
. IDE , ,
. IDE Pascal ABCNet
,
http://pascalabc.net.
IDE.
IDE ,
(. 181).
,
.

. 181 - IDE Pascal ABCNet

F9
.
, ,
(. 182).
554


IDE Pascal ABCNet

. Enter
. ,
Ctrl+F2.

. 182 -


, .
(. 183), (
).
IDE Pascal ABCNet , ,
IDE Borland Pascal , .
Net ,
.

555


IDE Pascal ABCNet

. 183 -

, , 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

FOR-DOWNTO-DO

ELSE

EXPORTS

IF, CASE
BEGIN-END, CASE-END, ASMEND, RECORD-END
DLL

FALSE

FILE

FOR

FOR-TO-DO

FUNCTION

GOTO

IF

IF-THEN-ELSE

IMPLEMENTATION

IN

INHERITED

INLINE

INTERFACE

LABEL

LIBRARY

MOD

NIL

END

557

NOT

OBJECT

OF

CASE-OF-END

OR

PACKED

()

PROCEDURE

PROGRAM

RECORD

SET

RECORD-END
REPEATUNTIL
SET OF

SHL

SHR

STRING

THEN

IF-THEN-ELSE

TO

FOR-TO-DO

TRUE

TYPE

UNIT

USES


REPEATUNTIL

VAR

WHILE

WHILE-DO

WITH

WITH-DO

XOR

( )

REPEAT

UNTIL

558

,
.

Borland Pascal

ABSOLUTE

ASSEMBLER

EXPORT

EXTERNAL

FAR

FORWARD

INDEX

DLL

INTERRUPT

NAME

DLL

NEAR

PRIVATE

PUBLIC

RESIDENT

DLL

VIRTUAL

559

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

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

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.

51

Invalid PUBLIC definition


PUBLIC ,
.

562

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

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

,
, .

59

563

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

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

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



.

117

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 .
.

123

566

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

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

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

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

$UNDEF

$IFDEF

$IFNDEF

NNN

NNN,

$IF

NNN

NNN.

NNN

,
NNN .

$ELSE $ENDIF.

NNN

,
NNN .

$ELSE $ENDIF.

$IFOPT

,
() .

$ELSE $ENDIF.

$ELSE

,
,
.
$ENDIF.

$ENDIF

572



IDE Free Pascal Borland
Pascal.

MS-DOS

Borland Pascal

573

574

(Ctrl+F8)

575


Borland Pascal

576


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

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

579


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, )

Eof(F),
SeekEof(F)


.
TRUE,
(SeekEoln ).
TRUE,
(SeekEof ).

Read(F, )

, .

Readln(F, )

Close(F)

F.

Writeln(F, )
Eoln(F),
SeekEoln(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)

Chr(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

MyLibr

P_59_1

P_61_1

Turbo Vision

P_61_2

P_61_3

61

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. . + =. .: , 1989.
10. . ., . ., . . 100 .
.: , 1993.
11. . .
: . .: , 2006. 366

12. . ., . ., . ., . .
. .: , 1990.
13. ., .. Turbo
Pasca 7.0. .: -, 1995.
14. . .
.: , 1979.
15. . ., . ., .. .
1989-1996. .: ABF, 1996.
16. . . . 1-3, .
. .: , 2000.
17. ., ., . : .
.: , 2001.
18. . . . .: ,
1978.
19. . ., . .
. , - , 1993.
589

20. . . (+CD).
.: , 2006.
21. ., ., ., .
. .: , 1997.
22. . . . , , 1993.
23. . . (
): . , - , 1996.
24. . . . .:
, 2001.
25. . ., . . 100 . , -
, 2000.
26. . ., . ., . . .
, - , 1998.
27. .., ..
( 5.5) .: 1992.
28. ., . . . .:
, 1989.
29. . C++. .
. . . , -, :
, 2003.
30. . , . . .
. . - : , 2005. 416 .
31. . . .: , 1982. 288 .
32. .. 7.0. : .:
, 2007, 576 .
33. .. 7.0. .
.: , 2007, 416 .
34. . Borland Pascal: Turbo Vision 2.0
: 1993.
35. . Borland Pascal :
1994.
36. .
, 2003

37. . : . ., , 1995.
38. .. Turbo Pascal 7.0 . ., , 2003.

590

.,

Вам также может понравиться