Professional Documents
Culture Documents
,
,
,
, MSc ,
,
, . ,
/ ()
........................................................................................9
.............................................................................13
1. ................................................................................25
2. ........................................................................39
3. .................................................................75
4. ................................................................109
5. .................................................................................129
6. ..............................................................145
7. ...........................................................155
8. .............................................................................165
9. ......................................................................................................181
10. ...................................................................................193
11. ..........................................207
12. .....................................................................223
13. ..............................................................233
14. - ........................................................................241
..................................................................................................255
,
, ,
. , ,
.
,
,
, ,
, .
. , ,
. ,
. . , , , ,
.
, , , , .
14 ,
.
:
10
,
: , , ,
, ,
,
,
,
,
, .
, .
.
, , ,
/ , .
, , , -
11
.
,
, 50 ,
.
,
, , .
, .
,
. .
, (..
, , ..),
, - - .
14
,
. ,
. . ,
.
,
:
,
, ,
,
,
,
.
. . :
:
,
,
,
15
,
,
/
,
,
,
,
,
,
,
,
,
,
.
. .
:
,
16
,
, ,
,
,
, ,
,
.
,
:
,
,
,
,
.
, , :
,
,
17
,
,
.
.
, ,
.
.
, .
.
,
. ,
.
:
,
,
,
,
,
,
.
18
, ,
.
:
,
,
,
.
, , .
( ).
. .
.
.
/ . , . ,
.
19
, (.. , ..), , .
.
.
. :
,
,
( ) .
B
( )
B
( , )
B
( )
( )
( )
. .
20
, 58
(29 ). , ,
.
,
,
.
, , ,
.
, .
. , , , ,
.
:
,
, ,
,
,
,
,
,
.
21
.
.
,
:
: , .
: , ,
.
:
.
: , .
.
.
. ,
, . , ,
,
, , . ,
,
22
, .
. ,
. , ,
. . , .
, , :
. ,
.
-. ,
. ,
, .
. ,
. . ,
.
.
. :
, ,
,
.
23
. ,
, . ,
.
, .
. , . .
.
,
, , .
.
1.1.
.
26
1.2.
, :
,
,
,
,
,
.
1.3.
:
1.
.
.
.
2.
,
. , , , , .
, .
3.
. -
27
. .
)
1.
1.4.
(2)
1
1 :
,
,
28
(
)
( , , , )
,
, ,
( 1.2.1).
, :
5
1 2.
:
1 2.
1 . (
).
.
.
29
1.
2.
3.
4.
,
, .
5.
1.
. .
2.
..
3.
4.
1 :
2 :
1: 2:
3 :
3:
4 :
5 :
4:
2
2 :
30
(
)
,
, ,
( 1.4.).
, 1, ( 1.4.).
.
, :
31
3
4 5 ( ).
5
.
:
3 4.
1.
2.
3.
1.
:
)
)
)
)
2.
)
)
)
)
32
1.
..
2.
. .
1 :
2 : 3 :
1 : , ,
2 : , ,
1: 2:
1.5.
.
:
.
.
.
1.6.
,
.
http://members.tripod.com/~ideas/workshop.html
http://www.wcape.school.za/malati/Probsolve.htm
33
http://www.viabilitygroup.com/Pages/ProbSolvOTL.htm
http://www.stemnet.nf.ca/Curriculum/Math/Intermediate/problems.htm
http://www.roma.unisa.edu.au/11571/module3_11571/index.htm
http://www.hsdg.com/ps.htm
1.7.
1.
- :
( ), ( ),
( ), ( ),
2.
(
;), , .
3.
4.
1.2.
5.
6.
1.5.
7.
1.6.
8.
, .
9.
:
. , -
34
.
(
, , ),
,
.
. ,
, .
1.8.
1.
,
,
.
)
,
( ).
15 ,
15 . ,
.
.
, , .
2.
. . : , .
, .
35
3.
: ) , , , , , ) , , , , .
4.
, ,
.
5.
.
( ) .
. .
.
.
. (query)
, .
6.
.
. .
. , , . : ( ),
( ), (
), ( hackers).
36
1.
.
, , .
: , .
, .
( ) ( ) . .
.
.
2.
.
.
,
. ,
. ,
, . , , .
3.
.
: ) : server, , , ) :
, scanner, videocamera, , , ) -
37
2.1
,
.
40
2.2
, :
.
,
2.3
:
, .
. .
41
.
.
.
. 2.9.
2.4
(3)
1
.
, .
42
: , .
: .
: .
: .
:
.
,
2.1 2.4.2 . 5 1-8 .
1 2
.
1 2 , 1 2
.
10 15
43
1.
2.
3.
4.
5.
6.
, ,
.
7.
8.
9.
10. :
)
11. :
)
) /
12. :
)
44
) )
13.
138
) =138
) =:138
) :=138
) 138
14. :
) )
)
15. :
) A+B = 10
) A B*3
) A+B 12
) A 2*B 22
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
2
:
45
, .
.
. .
.
.
.
.
. .
,
2.4.3 2.4.5 . 10, 11 .
3 5
.
46
4, 6 8 ,
5, 7 9 .
8 12 .
1.
2.
, .
3.
( ).
4.
5.
6.
7.
:
) )
) )
8.
:
) )
) )
9.
47
10. 2 :
)
11. 2 :
)
12. :
)
48
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
3
:
.
.
.
, .
:
.
49
: :
)
<>
<>
1 2 _
. , .
,
2.4.5 2.5 . 2.4.5
.
9, 12, 13
.
5 6
.
3, 5 7 ,
3, 7 8 .
50
8 12 .
1.
,
, .
2.
3.
4.
M ...
.
5.
__
.
6.
i .. .. .. .
7.
_______________ , .
8.
() ______________
9.
_
______________
10. ______________ 1 2 _ .
11. _____________ , .
51
12.
_____________ ..
1:
2:
3:
4:
5:
6:
7:
8: _
9:
10:
11:
12:
2.5
.
.
2.6
,
.
2.7
1.
. 2.1 .
2.
. 2.1 .
52
3.
.
2.2 .
4.
;
, .
5.
. 2.3 .
6.
/ ; ( , ),
, , .
7.
. 2.4.1
.
8.
. 2.4.2
9.
. 2.4.5 .
10.
. 2.4.3 .
11. . 2.4.4 .
12.
. 12
53
13. . ; 12 .
2.8
1.
L, g
T 2 * 3.14 * (L/g)
T
2 .
Euro 330
lira 550
dollar 280
marko 100
synolo 1025*lira+2234*dollar+3459*marko
synolo
: , .
3.
1.
_
ATHR 0
i 1 100
54
HLIKIA
ATHR ATHR+ HLIKIA
_
MO ATHR/100
// O //
_
2.
5 .
R 0
i 1 5
VATHMOS
VATHMOS>100 ATHR R+VATHMOS
_
// ATHR //
4.
1.
2.
3.
4.
5.
6.
5.
// AN, AZ //
AN<0.35
55
A<0.17
6.
3 ( 1) . :
>18
-
_
7.
// MISTHOS//
MISTHOS<150000
EISF1 0.05*MISTHOS
EISF2 0.04*MISTHOS
_ (ISTHOS>150000 MISTHOS<250000
EISF1 0.075*MISTHOS
EISF2 0.06*MISTHOS
_ (ISTHOS>250000 MISTHOS<400000
EISF1 0.095*MISTHOS
EISF2 0.08*MISTHOS
_ ISTHOS>400000
EISF1 0.12*MISTHOS
EISF2 0.11*MISTHOS
_
ESIF1, EISF2, MISTHOS-(EISF1+EISHF2)
56
8.
To _1
3 ( ) .
MIN MAX .
1000000
0
.
9.
57
// //
=1
_ =2
_ =3
_
10.
// E1,E2,E3,E4,E5,E6,E7,E8,E9,10 //
ATHR E1+E2+E3+E4+E5+E6+E7+E8+E9+10
MO ATHR/10
E1>MO 101
E2>MO 102
E3>MO 103
E10>MO 110
10
.
(.. ) .
58
1.
200 , ( )
10.
2.
xronos 0.5
arhiki 295600
prosfora 256000
deval 1-(prosfora/arhiki,1/xronos)
deval
arhiki, prosfora, xronos.
: .
. .
deval 1-(prosfora/arhiki) ^ (1/xronos)
3.
poso 50000
agores 0
euro 330
flag
_
eidos
timi eidos/euro
59
agores+timi<=poso*euro
agores agores+timi
flag
_
flag=
4.
x=13 x 40, 20, 10, 5, 16, 8, 4, 2, 1
x=9 x 28, 14, 7, 22, 11, 34, 17, 52, 26, 13, 40, 20,
10, 5, 16, 8, 4, 2, 1
x=22 x 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8,
4, 2, 1
x=1.
5.
3 ( 1).
6.
. 100ml
.
_
// _, _B, _, _ //
_ 195/3
_B 205/4
_ 400/5
_ 450/5.5
_
60
i 1
_<
_
i 2
_
_<
_
i 3
_
_<
_
i 4
_
// i, //
_
7.
2 .
.
8.
// s1, s2, s3 //
s1 0
s2 0
s3 0
i 1 100
=1
s1 s1+1
_ =2
s2 s2+1
_ =3
s3 s3+1
61
_
_
// s1, s2, s3 //
9.
_
! price capacity
, donation
price1,capacity1
MAX capacity
cost price1
price2,capacity2
capacity2>MAX
MAX capacity2
cost price2
_
price3,capacity3
capacity3>MAX
MAX capacity3
cost price3
_
donate1, donate2, donate3, donate4, donate5
count 0
donate1>=cost count count+1
donate2>=cost count count+1
donate3>=cost count count+1
donate4>=cost count count+1
donate5>=cost count count+1
// count //
_
2.9
, . -
62
)
1. , . (+).
. ,
.
(infix) ,
. , :
+
, .
, . , =
. . :
BASIC,
- LET, .. [LET] x=a+b.
C .
Pascal :=... x:=a+b.
H COBOL ..
ADD A TO B GIVING X
- COMPUTE, ..
COMPUTE =+
y x*
63
y .
,
y *(+)
,
.
:
_1
//, , //
y *(+)
// y //
_1
, , ,
. , .
. - (bold) . .
)
.
2. , , . (+)/.
2, .
2 .
=0 .
- ....
64
_2.
// , , , //
*(+)
0 y /
// y //
_2
,
....
(sequence). ....
... , . . , _. ..
<>
<_1>
<_2>
...............
<_>
_
, .
<>
<>
_
_2 . =0;
.
)
...... . ..
65
_2.
// , , , //
*(+)
0
y /
_
// y //
_2
, . ..
_2.
// , , , //
flag
*(+)
0
y /
flag
_
// y, flag=, //
_2
(), , y flag. ..
_2.
// , , , //
flag
*(+)
0
y /
flag
_
// y, flag //
_2
66
,
. y, y. ,
, , , .
, :
I)
, -. .
3. 3 x, y, z. .
()
.
.. .
.
, .
)
Max
// x, y, z //
x
y> y
z> z
// //
Max
)
Max
// x, y, z //
x
y>
y
z>
67
z
_
_
// //
Max
)
Max
// x, y, z //
x
y>
y
_ z>
z
_
// //
Max
() <> ......
.... . ......_, ().
. () () .
_, ......_ _.
)
, .
, .
4. 1
100.
.
68
100 1, 2, .. .
1 . ...
. 1.
, i, 1 100
1. (counter).
i i+1
, . : i .
i 1.
100. i=100 ...,
(goto),
. <>
.
i 1
i<= 100
i
i i+1
_
69
.. .
2 . ......
.
. ,
.......
:
i 1 100
i
_
, . , .
.
5. 1+2+3+...+100.
, .
. ,
() .
, S i. :
SS+i
: S i. S
.
( , ).
:
70
S 0
i 1 100
S S + i
_
// S //
T
i S.
, S i,
,
. 1, 2, 3, 4 ... i 0, 1, 3, 6, 10 ... S.
( 100), // //
.
6. .
. !=1.2.3...(-1).
P .
P=0. , .
_
// //
P 1
i 1
P P * i
_
// P //
_
. ! .
, .
71
7. 1+3+5+....+99.
,
4, 5 6
. . ...... :
i 1 99 _ 2
.
, ,
.
<= > 0
>= < 0
0
, . .
x -10 10 _ 0.01
y x^2 - 5*x + 6
x, y
_
8. a b, a<b.
_..._
. . , .
_
a
b
_ a<b a>0 b>0
72
(data validation). _. .
, , .
. .
,
.
. , , . , .
.
.
a^2 a2, a(i,j) a[i,j] aij .
,
=0 ....
.
( ...) _, _
_... ,
. ,
73
, ,
.
.
( ) , (.
J.Martin, Diagramming Techniques for Analysts and Programmers, Prentice Hall,
1985)
. , . 2 .
3.1
( )
, . ,
( ).
76
3.2
, :
, , ,
.
.
3.3
, . ,
.
.
3.4
(3)
77
1
,
3.1 3.3
78
,
3.1
3.3 .
1, 2, 3, 4
. 1
1 2 .
1.
1,90.
.
2.
3.
4.
5.
1:
4:
2:
5:
3:
79
3.4 3.6
LIFO
,
.
6 4 .
80
1.
2.
- /, .
3.
: , , . ,
. , : , , ,
, , .
, , . , , , , , , , , , . /, , , ;
1:
2:
3:
3 3!=6. ,
, , , .
.
81
, , , , , ,
, , , , , ,
, , , , , ,
/
.
3.7 3.9
,
.
82
,
6 3 4 .
1.
2.
3.
4.
,
.
5.
6.
7.
8.
83
1:
4:
7:
2:
5:
8:
3:
6: ( )
3.5
.
:
,
; .
, (heap) .
; .
3.6
,
.
3.7
1:
3.1
84
2: 3.1
3: 3.2
4: 3.2
5: 3.2
6: 3.2
7: 3.3
8: 3.4
9: 3.4
10: 3.5
11: 3.5
12: 3.8
13: ab,
a b .
\\ a, b \\
b = 0
power 1
(b MOD 2) = 0
power (a*a, b DIV 2)
14: 3.6
15: 3.6
16: 3.7
17: 3.7
85
3.8
1
table
. min_age max_age
, min max
.
// table//
min_age table[1]
max_age table[1]
min 1
max 1
i 2 300
table[i]<min_age
min_age table[i]
min i
_
table[i]>max_age
max_age table[i]
max i
_
_
min, min_age, max, max_age
2
( n-1). , ( flag), -
86
. , , .
2
// table //
_
flag
i 1 n-1
table[i+1] < table[i]
(table[i+1], table[i])
flag
_
_
_ flag=
// table //
2
3
(push) (pop)
. , done, . , top . , stack size. item .
// top, item //
top<size
top top+1
stack[top] item
done
done
_
// top, done //
87
// top //
top<=1
item stack[top]
top top-1
done
done
_
// item, top, done //
top<=1 . , .
4
. , done, . , rear front , queue size. item
.
__
// rear, item //
rear < size
rear rear+1
queue[rear] item
done
done
_
// rear, done //
__
__
// rear, item //
88
done
_
// item, rear, done //
__
rear<=front .
.
5
.
.
3.7 2.
6
,
3.7. n-1 10 , 10 .
1
currency 5x2,
(
),
. ( ) nomisma1 nomisma2,
89
1 6.
. , poso1
nomisma1 , poso2 nomisma2 .
_
// currency //
nomisma1,nomisma2,poso1
nomisma1=6
poso2 poso1 * currency[nomisma2,2]
2
scores 5x5,
, . ,
5 sum. first (max).
// sum, scores //
i 1 5
sum[i] 0
_
i 1 5
j 1 5
sum[i] sum[i]+ scores[i,j]
_
_
max sum[1]
first 1
i 2 5
90
3
straight insertion sort).
.
(destination sequence) table[1], table[2], ..., table[i-1]
(source sequence) table[i], ..., table[n]. , , .
.
.
_
\\ table \\
i 2 n
temp table[i]
table[0] temp
j i-1
temp<table[j]
table[j+1] table[j]
j j-1
_
table[j+1] temp
_
\\ table \\
_
91
3.1. .
.
52, 12, 71, 56, 5, 10, 19, 90 45. . , .
.
. , 10 71, 56, 52, 12 5, 10 5 12. 12
71
10.
( Pascal)
.
table n+1 , , table[0], -
92
. .
,
.
4
, CD. CD, . , CD.
5
5.
3.9
.
3.9.1
H :
.
n-1 ,
. (straight selection
sort) .
, -
93
. , ,
.
. . ,
, . , 5 ,
52. .
.
.
3.2. .
94
3.9.2
(merging) . ,
(, ) .
.
x y, n m , z n+m . , i, j k x, y z. .
x y z .
. z.
// x(), y(), n, m //
i 1
j 1
k 1
O i <=n j <=m
x[i] < y[j]
z[k] x[i]
i i+1
z[k] y[j]
j j+1
_
k k+1
_
i > n
t j m
z[k+t-j] y[t]
_
t i n
z[k+t-i] x[t]
_
95
// z() //
3.9.3
.
(pointer) , ( , , .)
. 3.3 , , info,
, , next,
.
3.3.
.
.
3.4.
__
// p:
data:
q: //
q.info data
q.next p.next
p.next q
__
96
3.5.
: p , p.info
p.next
. ( q), .
3.6.
, . , p
, . ,
( ).
__
// p: ,
//
q p.next
p.next q.next
__
(dynamic),
. ,
,
. (-
97
3.7.
3.9.4
, , .
.
.
(graphs). :
.
(root) , -
98
. , . ( ) .
.
(father) .
(children) . .
3.12
.
(degree) .
. n n- (n-ary) . (binary), (ternary) (quadtree).
(terminal
nodes leaves). (internal nonterminal nodes branches).
( ) 1.
(depth)
(height) . 3.12 3.
,
.
A .
, .
. .
, (nil).
n+1 , n
. 3.8
3.12 ( ).
99
Left
Info
Right
3.8
. .
.
.
3.9.
3.9.
100
.
, (
). . 3.9 35
Search-Node.
Search-Node
// Root : , : //
Root
nil =
.Info = =
> .Info B.Right
B.Left
_
_
_
// .
//
Search-Node
, , B.
Info B.Left, B.Right
.
:
,
. . .
. , . , .
.
101
(traverse). .
.
. (root)
.
(subtrees).
.
.
1.
2.
3. .
2 3
.
( 1, 2, 3), (preorder). 3.12
:
.
()
Preorder-Traversal.
Preorder-Traversal (R)
// R: //
102
R nil
T R.Info
= R.Left
Preorder-Traversal ()
= R.Right
Preorder-Traversal ()
_
// //
Preorder-Traversal
. .
2, 3, 1
(postorder)
3.12 :
A
.
2, 1, 3
103
(inorder) , :
.
, ,
.
1951 Jan Lukasiewicz
.
-
(polish notation), .
. :
1. +
2. ( + ) .
.+
3. + ( . )
+.
4. . + .
+..
.
+ + , +
. (-)
, (.. -)
(unary) (.. -).
.
- , + (-)
+ - .
104
, (reverse polish
notation). :
1. +
2. ( + ) .
+.
3. + ( . )
.+
4. . + .
..+
. ..
. + . 3.10.
3.10
, (prefix) :
+..
, (postfix) :
..+
,
(infix) , :
.+.
105
, .. APL
FORTH. (.. Hewlett- Packard).
.
. .
, :
ADD
.
MUL .
O ,
push . ,
ADD MUL ( ). . + ( +.) :
PUSH
PUSH
PUSH
MUL
ADD
.
3.9.5
,
106
.
,
. (graph). 4.1 ( )
. O . , ,
- .
a, (adjacency matrix). , nxn, n . aij 0 i j ,
aij (weight)
, .
. (symmetric), aij = aji.
13
13
10
11
, ,
aij = aji. ,
, .
,
. ,
1. , (binary) , 0 1.
107
. , ,
.
Leoard Euler
Koenigsberg, 1736. Koenigsberg Pregel,
2 7
. Koenigsberg
, . Euler .
Kirchoff, 1847 ,
Cayley
.
4 ,
4 ,
.
1850 1976.
108
3.10 3.2
( 51).
. ( ) ,
. ,
24 2 ,
,
,
.
24 , ( , , ..). ,
.
,
. ,
. .
4.1
.
,
.
110
4.2
, :
,
.
.
.
.
4.3
: .
.
, .
. ,
. ,
( 3
) . ,
.
111
4.4
(2)
1
:
.
.
, .
. .
.
. . .
112
.
.
.
.
, . 4.1 4.3 . 1-4 .
.
1 2 .
2 3 , 1,
2 4 .
1.
, .
2.
3.
4.
() .
5.
6.
113
7.
8.
- .
9.
:
)
)
)
)
10.
:
)
)
)
)
11. :
)
)
)
)
1:
2:
3:
4:
5: 9:
6: 10:
7: 11:
8:
114
2
:
.
.
.
, .
. .
.
.
.
115
, . 4.4 4.5 . 5-8 .
. 3 .
1 - 3, 5 6
.
1.
2.
, .
3.
, .
4.
_______________
.
5.
_________________ ,
__________________.
6.
_____________ , -
116
1:
2:
3:
4:
5:
6:
4.5
,
.
.
4.6
,
.
4.7
1:
4.1 ( ).
2:
4.1 ( )
3:
:
( )
( ).
117
4:
4.3 .
5:
4.4 .
6:
4.3 .
7:
N
!.
. , ( ).
8:
, ab,
a b 3. ( )
( ), (1, 2, ,
b-1) b.
\\ a, b \\
power[1] 1
i 1 b
power[i] power[i]*a
_
\\ power[b] \\
3
.
power . , 2,
1 0, 2 1, 4
2, 16 3 ... .
0
1
0
1
2
1
2
4
2
3
16
4
4
256
8
. 27,
118
4 2, 27 = 24 *22 *21.
ab .
\\ a, b \\
power[1] a
i 1
pow 1
power < b
i i+1
pow 2*pow
power[i] power[i-1]*power[i-1]
_
used 0
result 1
used < b
used+pow <= n
result result*power[i]
used used+pow
pow pow/2
_
i i-1
_
\\ result \\
4.8
1.
.
.
119
([1],[pos]) [1] [pos]:
_
// //
low1 M[1]
pos 1
i 2 50
M[i] < low1
low1 M[i]
pos i
_
_
([1],[pos])
low2 M[2]
i 3 50
M[i] < low2 low2 M[i]
_
// low1 , low2 //
_
2.
3.6
4.3 2 4 . .
3.
.
.
120
4.
. , ( ).
.
1.
10 0 .
_
// number //
low 0
high 10
found 0
number
low <= high
mid (low + high)/2
mid < number
low mid+1
_ mid > number
high mid-1
found 1
_
_
// found //
_
121
2.
4.3 2 4 .
3.
xn
4.
4.3 2 4 .
5.
. VATH
. 20 .
1000 :
SUM VATH[2O]
i 19 1 -1
SUM+VATH[i] < 1000
SUM SUM+VATH[i]
stop i1
_
_
122
stop
.
6.
5 .
4.9
.
4.9.1
.
(quicksort). ,
,
(bubblesort) . n
. n/2
, .
. .
_.
,
.
,
. , -
123
,
, . . , , , .,
. , .
_
// table, left, right //
right > left
i left
j right+1
pivot table[left]
_
_
i i+1
table[i] pivot
_
j j-1
table[j] pivot
i < j (table[i], table[j])
i j
(table[left], table[j])
_(table, left, j-1)
_(table, j+1, right)
_
// table //
_
. (. 4.1).
, pivot = 52
. , 52.
71 ( i). ,
52, 45 (
j). 71 45, , 4.1. -
124
52
52 . , 56
( i) 19 ( j), (. 4.1).
56 ( i)
10 ( j). i > j,
.
j. , 52
10, (. 4.1).
4.1
_.
-.
- ,
52. ,
. 52
-, 3
52. .
52
4.2
_.
125
_
.
4.9.2
.
, .
(backtracking) , ,
, .
,
4.1 ( ) . , :
1)
,
( ),
,
.
2)
, ,
.
, . , ,
/. (),
, .
126
. , ,
, .
.
7 7 . , , . ,
,
.
.
Hampton Court Palace, 3 .
4.3.
, 19 .
,
, .
,
.
4.4
4.3.
127
4.4
128
, (1),
1,
mark(1)=. 2 1 ( a(1,2)=1) (2).
2 ( mark(2)=),
2.
( 2) ,
(backtrack) 1. 3
(3), a(1,3)=1 4 (4). 4 () 3, (5). , 1, 2, 3, 4, 5, 6, 5, 7, 8, 9, 10, 11, 12, 13,
mark.
. , ( 2, 4, 6, 12 13).
. , ,
. ,
, ,
, ,
, .
, ,
, .
5.1
.
.
130
5.2
, :
.
.
.
.
.
5.3
:
. ()
.
5.4
(2)
131
1
.
.
.
, .
: ( )
.
: .
: (size) .
: .
:
.
132
: .
, : 5.1 5.2 . 1-8 .
:
1 2 .
1 2 1,
2 3 .
1.
2.
3.
4.
5.
6.
133
7.
8.
9.
. :
)
:
)
10
. , :
)
10.
:
)
134
11.
)
12. :
)
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
2
.
.
135
, .
. .
. .
.
.
, . 5.3 5.4 . 9-13 .
.
3 4 .
3 4, 4 5.
1.
136
2.
f(n),
O(g(n)) c n0, nn0
: f(n) c g(n) .
3.
(n).
4.
5.
O(logn).
6.
O(n)
n .
7.
______________
,
.
8.
__________________ .
9.
_________________
.
1: 4: 7:
2: 5: 8:
3: 6: 9:
5.5
, . , -
137
, .
, , .
, , , . .
.
5.6
,
.
5.7
1.
5.1
2.
5.1
3.
5.1
4.
5.1
5.
5.1
6.
( )
. , , .
7.
5.2.
8.
5.2.
138
9.
5.3.
10. 5.3.
11. 5.3.2
12. 5.3.2 3 4 3
13. 5.4.
5.8
1.
1.
. n/2, O(n).
2.
/ .
n
1 = n = n
i=1 j=1
i=1
, (n2).
3.
.
n/ 2
n/ 2
1 = n = n
i=1 j=1
/2
i=1
, (n2)
, , .
139
2:
donation ( 30 ),
.
sum.
_SOS
// donation //
sum 0
i 1 30
sum sum+donation[i]
_
sum
_SOS
. (n).
3:
Fibonacci .
. ,
n~)~0 . , n n DIV 2. (logn). 3 ( ),
.
4:
, ,
.
. 1960, / , .
.
140
1:
1.
n=100 .
, O(n).
2.
3.
.
(n-1)/3, . O(n).
2:
( ) 1 1,
(n).
3:
_ ( 4.3 ) .
KAT[mid]~(~ONOMA,
. .
(high-low) . log(high-low). (logn). 10 ,
.
4:
. , (n2). ,
.
141
2 .
(n-1 n),
.
5:
19??. .
. , , ,
. ,
, .
.
5.9
: .
. n C .
li , li < C 1 i n. n
,
.
n = 6 c = 100, 50, 60, 30, 70,
50 40 .
. n! =
6! = 120, n . n ,
, (optimal).
, n , .. 1000, ( 1000!), -
142
.
(suboptimal)
, .
, 3. ,
1 5, 2 6 3 4 , 100 ,
.
,
. , first fit. , . ,
, .
, . .
:
.
:
:
1
2
3
4
5
6
7
8
n. C.
li, li < C 1 i n.
X.
1,2,...,n.
1,2,...,m.
i=1. j=1. X=1.
i- j- , ,
6,
j=j+1.
j>X, X=j 4.
i=i+1.
i n 4 8.
.
143
, 4
(1,3), (2,6), (4) (5) .
. first-fit 70% .
6.1
.
146
6.2
, :
.
.
.
.
.
.
.
.
6.3
, .
.
.
.
,
.
147
6.4
:
(1) .
, , .
1
.
.
.
.
.
.
4 .
.
.
148
.
.
.
.
.
Go To .
.
.
.
.
.
- .
.
.
1, 2.
1 .
1
. ,
, .
, .
,
. ,
.
149
.
1.
2.
3.
4.
.
.
5.
6.
Basic
.
.
.
. .
7.
: .., ..
8.
.
....
150
1.
2.
3.
4.
5.
6.
7.
, ,
8.
6.5
. ,
.
, , , .
6.6
,
.
:
http://devcentral.iftech.com/learning/tutorials/
151
6.7
6 .
1.
6.1
2.
6.2.1
3.
6.2.3
4.
6.2.3
5.
6.2.3
6.
6.3
7.
6.3
8.
6.4.1
9.
6.4.3
10. 6.4.3
11. 6.5
12. 6.7
13. 6.7
14. 6.7
152
6.8
1
2
3
4
1
5
_
_
1
.
:
153
Pascal
154
1
1
2
2
3
4
_
5
_
3
7.1
,
.
156
7.2
, :
.
.
.
.
.
.
7.3
,
. ,
.
.
, .
, .
.
,
-
157
, .
. , Pascal
Basic, .
7
, .
.
, .
, ,
.
,
, ,
.
7.4
:
(1)
158
1
.
, , .
159
,
.
1 2 , 1
.
,
. , ,
.
1.
2.
3.
.
4.
) <-+1
) <- +1
) <- 1
) +1<-
160
5.
:
<- (5+4/2*2)*2-(3*2+5-3)^2+9/3-2
) -53
) -37
) -125
) 45
6.
.
=3.14
.:,
<- *^2
:, ..
..
1.
2.
3.
4.
5.
6.
, , , _
161
7.5
,
.
:
http://pascal.miningco.com/
Pascal. .
http://www.angelfire.com/pa/rjolliff/
Pascal.
http://www.xs4all.nl/~dgb/delpascl.html#A_SITES
Pascal.
7.6
7 . :
1.
7.2
2.
7.3
3.
7.4
4.
7.7
5.
7.9
6.
7.9
7.
7.10
162
7.7
1.
1.
T<-2**_(/D)
2.
<-(m*v*u^2)/2
3.
F<-_(F1^2+F2^2+2*F1*F2*()
4.
<-(-+_(^2-4**))/(2*)
2.
1.
2.
3.
4.
5.
6.
( )
3.
:, , , ,
, ,
<-(++)/2
<-_(*(-)*(-)*(-))
_
163
.
, -, -, - , .
8.1
: , .
166
8.2
, :
, .
().
.
.
.
.
.
8.3
. 2.
Pascal
FOR Pascal . ( ) 1.
1,
for
( 3 )
. while, repeat if, case .
8.4
167
(2) .
1
, .
().
.
.
.
, , .
: , ,
168
-
- -
- _
,
8.1
1 .
1 2 . 3
1. 1
2.
1.
2.
3.
4.
10 20
( >8 <20) (>10 =10) .
169
.
5.
<-0
<-5
<-10
>10
>20
>10
2*
_
<10
_
_
. 0
. 10
. 5
. 20
6.
,
<
7.
170
0
<- _()
1 :
2 :
3 :
4 :
5:
6: , <-
7: >=,
2
.
.
.
, .
171
, , .
-
_
,
8.2
.
172
4 5
. 4, Internet, . , 3.
5 1.
.
.
1.
2.
- .
3.
,
.
4.
.
5.
<-10
<>0
1 5
<--1
_
_
173
. 10
. 0
. 2
.
6.
10.
<-
1 10
<- + ^2
_
7.
100 200
<-
<-
_
<-+
<-+1
_
1 :
2 :
3 :
4 :
5:
6 : 0, , 2,
7 : 100, 0, >200
174
8.5
,
.
:
http://pascal.miningco.com/
Pascal. .
http://www.netalive.org/ckb/
Pascal Delphi, .
http://www.angelfire.com/pa/rjolliff/
Pascal.
http://www.xs4all.nl/~dgb/delpascl.html#A_SITES
Pascal.
8.6
8 .
1.
8.1
2.
8.1
3.
8.1.1
4.
8.1.1
5.
8.1.1
6.
8.1.2
7.
8.2
8.
8.2.2
9.
8.2.3
10. 8.2.3
8.7
1.
.
2.
.
>
_ >=(-2)
.
( = 1 >15)
_
175
176
.
<> <> <> <>
_
.
<= 0 ()=0
<-(^2+5*)/(_()* ())
_
3.
. .
2>700
_ 2>500
_ 2>400
_
3 >500
_ 3 >300
_ 3 >250
_
177
4.
5 100.
.
<- 0
<- 0
<=100
<- ^3
<- +
,
<- +5
_
<- 0
<- 0
_
<- ^3
<- +
,
<- +5
_ > 100
. .
5.
.
<- 0
<> 0
<- 0
>
<-
_
<
<-
_
<- +
_
178
.
<- 0
_
<- 0
>
<-
_
<
<-
_
<- +
_ = 0
.
<-0
1 100
<- 0
>
<-
_
<
<-
_
<- +
_
179
8.8
. ,
, , , ..
. .
, .
. 1 10 ....
1 10, . . ,
.
1 10.
. , 1 10. ;
. . , ,
, .
, , .
. . -
180
, , , .
.
, .
, . Basic,
READ-DATA.
. 45 20 . m n .
.
.
.
,
.
9.1
182
9.2
, :
.
.
, .
.
.
.
.
9.3
.
.
.
,
.
3 4.
9.4
(2)
183
1
.
.
, .
.
, , .
184
9.1 .
1, 2 , 1
1 .
.
.
1)
2)
3)
4)
I.
.
5)
5
) :[5]
) :
) : [1], [2], [3], [4],[5]
) [5]:
6)
10
185
)
1 10
<-+
_
)
1 10
<-+
_
)
1 10
<-+[]
_
)
1 10
<-[]
_
7)
, .. .
8)
0
1 30
[..]<-0
_
1.
2.
3.
4.
186
5.
6.
7.
8.
2
.
.
.
, , .
.
.
.
.
.
.
187
,
9.3 . 3
.
3
4 , 2 4
5 .
.
.
1.
10
.
2.
3.
4.
.
5.
55
188
)
1 5
[]
_
)
1 5
[, ]
_
)
J 1 5
[J]
_
)
1 5
J 1 5
[,J]
_
_
6.
7.
55
1 5
<-.
J 1
<-+[,]
_
_
189
1.
2.
3.
4.
5.
6.
7.
0, 5,, I,J
9.5
,
.
:
http://pascal.miningco.com/
Pascal. .
http://www.netalive.org/ckb/
Pascal Delphi, .
http://www.angelfire.com/pa/rjolliff/
Pascal.
http://www.xs4all.nl/~dgb/delpascl.html#A_SITES
Pascal.
190
9.6
9 .
1.
9.1
2.
9.1
3.
9.1
4.
9.1
5.
9.1
6.
9.1
7.
9.1
8.
9.3
9.
9.1
10. 9.2
11. 9.4
12. 9.4
13. 9.4.
9.7
1.
.
:[5]
1 5
[]<-
_
.
:[10]
1 10
[]<--1
_
.
: [20]
1 20
[]
_
.
:[10]
<-500
1 10
[]<-
<-/2
_
2.
<-[1]
<-1
<-[1]
<-1
2
[] >
<-[]
<-
_
[] <
<-[]
<-
191
192
_
_
[], []
3.
1 4
J A 1 4
<>J
[,J]<-0
[,J]<-1
_
_
_
4.
I 1 5
<-[,3]
[,3] <-[,6]
[,6] <-
_
10
10.1
.
194
10.2
, :
.
.
.
.
.
.
.
.
.
10.3
.
.
. ,
.
.
195
Pascal
Pascal , functions procedures,
.
, , .
(in parameters value parameters)
(in- out parameters variable parameters).
, procedure difference (a,b:real;var dif:real).
,
.
Pascal .
Basic
QuickBASIC .
: QuickBASIC
.
.
.
QuickBASIC .
QuickBASIC , . ,
GOSUB.
. -
196
.
.
10.4
.
(2) .
1
.
.
.
.
.
.
, , .
197
,
10.1 10.6
.
198
1 2
, 1 1
. 3.
.
.
1.
2.
3.
.
4.
(=1/2**).
) (,)
)
) (,):
)
5.
<-10
<-5
(,)
,
199
(,)
..
<-0
<-0
,
..
10 5
00
10 5
10 5
00
00
00
10 5
6.
7.
1)
2)
3)
4)
5)
6)
7)
200
2
.
.
.
, , .
.
.
.
,
10.7 . 2 .
3
4 .
201
.
.
1.
2.
3.
4!
3!, 2!, 1! 0!
4.
:
.. .
1.
2.
3.
4.
10.5
,
.
:
202
http://pascal.miningco.com/
Pascal. .
http://www.netalive.org/ckb/
Pascal Delphi, .
http://www.angelfire.com/pa/rjolliff/
Pascal.
http://www.xs4all.nl/~dgb/delpascl.html#A_SITES
Pascal.
10.6
10. :
1.
10.1
2.
10.2
3.
10.4
4.
10.5
5.
10.5.1
6.
10.5.2
7.
10.5.3
8.
10.5.3
9.
10.6
10. 10.7
11. 10.7
10.7
1.
)
)
)
)
)
)
)
2.
)
(2)
,2
2<-^2
_
)
(,,)
,,
<
<-
203
204
<-
_
_
)
_(,)
:,
<-*0.18
_ _
)
():
:
mod 2 =0 TOTE
<-
<-
_
_
3.
:
()<-*(-1)
(0)<-1
(4)
4*(3)
(3)
3*(2)
(2)
2*(1)
(1)
1*(0)
(1)
205
(2)
2*1
(3)
3*2
(4)
6*4
:
1
<- *
2*3
6*4
11
11.1
, .
208
11.2
, :
, , ,
,
,
,
.
11.3
:
1.
2.
.
, ,
.
3.
209
4.
5.
.
.
.
6.
.
,
.
7.
(trigger events)
(cascading
events).
8.
, .
9.
. ,
, , ,
.
10.
.
11.
.
.
210
12.
.
11.4
(3)
1
:
, , ,
,
.
, , ,
211
,
.
. ( 11.1 11.2)
, :
1 2.
:
1 .
1.
:
1.
.
.
212
1.
2.
3.
4.
5.
6.
.
7.
..................
8.
..................
9.
.................. .
10. ...................
11. .................. .
213
10 :
11 :
2
:
,
,
,
.
214
, , ,
,
,
( 11.3.1).
, :
3 4.
:
2 2 3 .
2, 7,
.
215
:
2 3.
1.
2.
3.
4.
5.
.
6.
..
7.
8.
216
3
:
,
,
.
, , ,
217
,
11.3.1. 11, 12 13 .
:
3.
2,
.
4 .
5 6.
:
4.
4,
. Visual Basic
Font FontBold, FontItalic, FontSize,
ForeColor .
.
.
218
1.
2.
3.
4.
5.
.
6.
..................
7.
..................
8.
..................
219
11.5
.
:
.
.
.
.
.
11.6
, .
1.
2.
3.
220
11.7
. .
:
2
3
5
7
8
10
12
13
11.3
11.2.2
11.1.1
11.1.4
11.2
11.1.2
11.5.1
11.6
11.8
.
, .
221
3.
. -.
. .
. .
12
12.1.
( ) , ,
.
224
12.2.
, :
,
12.3.
:
, .
. ,
.
.
.
. ,
, . ,
.
,
. ,
.
225
12.4.
(1)
1
1 :
,
( )
,
, ,
(
)
( )
( )
( , )
226
,
,
12.3,
.
:
1
2
:
1
1 , .
:
1 2.
3 1.
, 3
.
.
.
227
1.
2.
3.
4.
GUI.
1.
2.
..
.
3.
...
1 :
1:
2 :
2:
3 :
3:
4 :
12.5.
.
228
12.6.
,
.
http://mjmi.engin.umich.edu/Conf/NO95/TALKS/TE14.1.html
http://explorer.scrtec.org/aux/about/wInterfaceInfo.shtml
http://www1.viaweb.com/softpro/misc-user-interface-design.html
http://www1.pitt.edu/~laudato/UI/
http://www.iol.ie/~nmurphy/hire.htm
http://www.acm.org/sigchi/chi97/proceedings/tutorial/dmh.htm
12.7.
1.
user interface, .
, (
). ,
, , .
2.
. .
. -
229
: , , .
3.
12.2.1.
4.
12.3.1.
5.
. .
.
6.
12.4.2
7.
. :
, .
12.8.
:
, . ,
.
1.
.
230
2.
.
. :
: ( ),
( ): (, , ).
1.
(project). .
, , (.. Visual Basic).
, .
:
,
,
231
,
,
,
,
.
1.
.
. .
)
2.
.
.
3.
,
1.
13.
280
, , , . , , .
, .
, .
,
,
, ,
.
:
.
.
.
.
3 ;
3 ;
3 ;
3
,
;
3
;
281
13.1
, , , .
,
.
, :
, . .
, , .
, , .
, . , . ,
.
,
(crash) .
,
.
(bug)
. ,
bugs, .
282
, ,
.
,
, ,
,
,
.
.
, .
(testing) .
2000 (millennium bug). ,
.
:
1962 Mariner 1 Canaveral
. ... (NASA) , -
.
. NASA
FORTRAN . 80 .
1990 AT&T, . 5
.
Pentium 1994 ,
.
Thomas Nicely Lynchburg
Virginia . ,
450
1995 Denver .
. , .
,
3,2 .
283
284
13.2
,
(debugging).
.
,
. .
, .
, , ,
. , .
.
.
13.3.
. .
. ,
.
,
.
(debuggers).
,
.
:
(watch expressions)
. ,
,
.
.
. 13.1.
(breakpoint) .
.
, .
, .
.
285
286
. 13.2.
(history)
.
.
, . (tracing) ,
.
.
. 13.3.
(.. , ), .
,
,
, .
13.4
.
, .
287
288
.
, .
. , .
, .
:
,
.
,
(exception error handler), . .
,
.
Java, ADA C++ (exceptions),
Visual Basic (On Error GoTo).
:
.
.
, .
, , , .
, . (..
) , .
, .
,
.
. ,
( ) .
.
.
.
.
.
,
.
, , , ,
.
-
1.
289
290
2.
3.
4.
5.
1.
, , 2, , 1986.
2.
. -. : Visual Basic
4.0, , , 1997.
3.
http://www.alsplace.com/home/pages/famous_bugs.htm
.
http://www.bugnet.com
.
http://www.guide-p.infoseek.com
.
http://www.netstuff.com/computerbug
.
http://www.techweb.com
, ,
2000.
http://www.year2000.co.nz
2000.
14
-
14.1
,
.
242
14.2
, :
,
, , ,
. ,
, , , , , ,
.
14.3
,
.
.
,
. .
. .
243
14.4
(2)
1
:
, ,
14.1. .
,
2 3 .
1, 3
4 .
244
1
2 , , .
1.
2.
3.
4.
5.
6.
. . 10
, 20.
1:
4:
2:
5:
3:
6:
245
.
.
, , , 7.
=6,
.
2
:
.
.
, ,
14.2, 14.3. ,
. VTOC .
246
,
7 .
5 , .
2, 1
2.
4 2 3 .
4
.
.
1.
2.
VTOC .
3.
4.
, .
5.
, , , , .
247
.
.
.
(VTOC).
XXXXXX
XXXXXX
XXXXXX
...............
XXXXXX
............................
XXXXXX
XXXXXX
...............
XXXXXXX
XXXXXXX
..................
.....................................
......................................
1: 2:
4: 5:
3:
XXXXXXX
XXXXXXX
..................
XXXXXXXX
248
14.5
.
:
. . .
,
, .
14.6
www.gold.net.au/~~other/techical/delphi-pascal/pascal-ArabicToRoman.html
249
http/hackensackhigh.org/roman.html
14.7 .
14 .
14.8 .
1.
. . :
..
!!
D<-0
d=0
1 7
=day()
D<-
<-8
_
_
_
day . d .
. 10, : 10 ; -
250
3 .
.
7 , .
, , .
2.
3, 5, 6 7.
.
..
<-
mod 4 = 0
<-
mod 100 = 0
<-
mod 400 = 0
<-
_
_
_
3.
: >, >, >.
,
3 .
>
temp <-
<-
<-temp
_
251
4.
3 . ,
. .
1.
(//) (.
). . 7 . 1 . 4 .
2.
() ,
21 .
3.
, 3, 4, 5, 6
.
252
1
2
4
5
4 .
, . 4 5 .
4.
2 3 . VTOC.
1.
1 .
2.
1 .
3.
.
253
.
1
2
3
4
5
6
7
8
9
10
11
12
0
31
59
90
120
151
181
212
243
273
304
334
20/5/
(5)+20=120+20=140 .
30 .
1
2
3
4
5
6
7
8
9
10
11
12
0
1
-1
0
0
1
1
2
3
3
4
4
254
20/5/ (5-1)*30+(5)+20=4*30+0+20=120+20=140 .
1/1/1,
.
.
4.
.
5.
12 (
4000).
, , .
.
. . .
,
.
. ,
, . O
.
.
. . K , .
.
. (program files), (text files), (binary files)
(executable) (data files).
. -
256
(directories).
1. -
(character) .
byte .
(field)
. , . (
) o ( . ). , .
, , .
(logical record) .
.. (record) .
(layout).
.
(file). . ,
.
. (key)
.
.
(. , , ) , .
, ,
257
.
( - dublicate keys). .. ,
, .
,
(primary key) (secondary alternate
keys). , .
2.
:
1.
(master files). .
(.. , , , ) ( , ). : ,
, ..
2.
(transaction files).
, .
. .
3.
(index files).
- .
4.
(auxiliary files). .. , , ..
5.
(work) (intemediary).
.
258
6.
(historical files). .
7.
(backup files). , . . .
3.
:
(retrieval) . . ,
.
, ,
.
(query). , . : 1 6,
,
10 200.000 ..
(updating). ( / ). : (addition) , (deletion)
(modification) .
-
259
.
.
( )
( ).
,
.
,
( ). .
(sorting).
.
(merging).
.
, sort-merge
.
(append) , , . (copy)
,
(back-up), ..
.
.
.
.
.
260
.
.
Update-File
=0 : E
--
E
-
-
- ()
Update-File
O -
261
, . ,
, . .
, .
, .. Enter ( ). ,
, .
A .
, .
.
4.
:
.
.. , , .
.
, . .
(.. byte).
.
. M
.
)
.
,
262
.
(line feed-carriage return)
. (EOF-End Of File)
.
,
.
)
, . (.. )
. .
,
, .
.
(trailers).
. , , .
,
.
.
.
.
(binary)
1
byte.
263
5.
.
. ,
, , , ...
. . ,
, , , . .
(fragmentation). ,
( ).
. . , -
.
, ,
.
. ( ) .
, ,
(buffer).
.
.
. () , .
264
.
, . .
(blocking) . (blocks)
.
(blocking factor).
, (inter record gap-IRG).
. 3/4 .
6.
(, , )
,
.
.
. :
( - interactive, - transaction
processing, - batch)
(, , )
.
265
- - : , .
7.
.
, (access methods)
/
.
, . .
, (sequential) (random).
,
.
. , , .
. ,
.
, . .
( ), , . ,
266
. ,
.
:
)
1 (seek time),
2 .
1+2. 2 , 1 , .
1 ,
,
. random. . .
.
8. (sequential organization).
, - , -1 .
.
, (key) . ,
.
, /2 , .
267
. .
, ( .. ).
(text
files).
.. . ( ), .
.
, , .
8.1
. .
.
, .
, , .
(validation) . K ,
, ,
:
268
1,
().
2, ,
()
3, .
. , (matching) :
, .
, (K=1), .
=2 , (=3).
, . .
,
(merging)
.
8.2 Y
Turbo Pascal
(text files) Turbo Pascal. -
269
.
- (end of line, eoln)
CR LF. -
(end-of-file, eof).
Input Output .
.
Turbo Pascal, Input, Output, :
: ,
. Input, Output.
Program _ ( _)
: , ,
.
text.
var
_:text
:
. Turbo Pascal assign.
Assign (_, -)
: , reset. reset .
Reset (_)
270
: rewrite
append. rewrite
append .
Rewrite (_)
Append(_)
: read, readln.
Read(_, )
: write,
writeln.
Write(_, )
: close.
Close(_)
eoln eof.
eoln - True. eof .
Eoln (_)
Eof (_)
QuickBASIC
T
. CR LF,
EOF (Ascii 26).
271
M OPEN
. :
OPEN _ [FOR ] S [#]_
. WRITE ,
.
INPUT :
INPUT #_, _
EOF(_) INPUT , .
8.3
1.
Turbo Pascal
program files1(input,output);
uses crt;
var
cod:integer;
per:string[20];
tm:integer;
q:real;
stock:Text;
begin
clrscr;
assign(stock,stock.dat);
rewrite(stock);
write(:);
272
readln(cod);
while cod>0 do
begin
write( :);
readln(per);
write( :);
readln(tm);
write( =);
readln(q);
writeln(stock,cod:3,per:20,tm:4,q:6);
clrscr;
write( :);
readln(cod);
end;
close(stock);
end.
Quick Basic
OPEN STOCK.DAT FOR OUTPUT AS #1
DO
INPUT =,cod$
IF cod$="" THEN EXIT DO
INPUT =,per$
INPUT =,tm
INPUT =,q!
PRINT#1,cod$;",";per$;",";tm;",";q!
LOOP
CLOSE
END
2.
To (dump)
.
Turbo Pascal
program files2(input,output);
uses crt;
var
273
xx:char;
grami:string[80];
stock:Text;
begin
clrscr;
assign(stock,stock.dat);
reset(stock);
while not eof(stock) do
begin
readln(stock,grami);
writeln(grami);
end;
close(stock);
write( ...);
xx:=readkey;
end.
Quick Basic
OPEN STOCK.DAT FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
LINE INPUT#1,z$
PRINT z$
WEND
CLOSE
END
( readln
LINE INPUT . ).
3.
274
Turbo Pascal
program files3(input,output,lst,stock);
uses crt;
const
max_crt=22;
max_prn=63;
var
xx:char;
cod,lines,choice,max_lines,pages:integer;
per:string[20];
tm:integer;
q:real;
stock,lst:Text;
procedure PRINT_TITLES(var lst:text;var lines,pages:integer);
begin
writeln(lst,
A
);
lines:=0;
pages:=pages+1
end;
begin
clrscr;
assign(stock,stock.dat);
reset(stock);
clrscr;
pages:=0;
writeln ( );
writeln;
writeln (
1.);
writeln (
2.);
repeat
gotoxy(5,5); write(:);readln(choice);
until (choice=1) or (choice=2);
if choice=1 then
begin
assign (lst,con);
max_lines:=max_crt
end
else
begin
assign(lst,LPT1);
max_lines:=max_prn;
end;
rewrite(lst);
print_titles(lst,lines,pages);
while not eof(stock) do
begin
readln(stock,cod,per,tm,q);
if linesmax_lines then
begin
writeln (lst,: ,pages:2);
if choice=1 then
begin
write( ..);
xx:=readkey;
clrscr; { }
end
else
writeln(lst,chr(12)); { }
print_titles(lst,lines,pages);
end;
writeln(lst,cod:5, ,per:20, ,tm:4, ,q:10:2);
lines:=lines+1;
end;
writeln (lst,: ,pages:2);
write( . ..);
xx:=readkey;
close(stock); close(lst);
end.
275
276
Quick Basic
E
k$ = : CLS
page = 1: lines = 100
PRINT
PRINT
PRINT 1.
PRINT 2.
LOCATE 7, 1: PRINT : .
DO WHILE VAL(k$) 1 OR VAL(k$) 2
k$ = INKEY$: LOCATE 7, 11, 1: PRINT k$;
LOOP
k = VAL(k$)
IF k = 1 THEN
OPEN O, #3, SCRN:: maxl = 22
ELSE
OPEN O, #3, LPT1:: maxl = 66
END IF
OPEN I, #1, STOCK.DAT
Printing
WHILE NOT EOF(1)
GOSUB ReadNextRecord
GOSUB PrintOneLine
WEND
CLOSE : END
ReadNextRecord:
INPUT #1, cod$, per$, tm, q!
RETURN
PrintOneLine:
IF lines maxl THEN GOSUB PrintTitle
PRINT #3, cod$; ; per$; TAB(30);
PRINT #3, USING #####; tm;
PRINT #3, USING #######.##; q!
lines = lines + 1
RETURN
PrintTitle:
IF k = 1 THEN
GOSUB Press: CLS
277
ELSE
PRINT #3, CHR$(12);
END IF
PRINT #3, .
. ;
PRINT #3, TAB(70); :; page
PRINT #3, STRING$(79, -)
page = page + 1: lines = 3
RETURN
Press:
LOCATE 24, 1
PRINT ...;
w$ = INPUT$(1): RETURN
OPEN . #3
.
, PRINT #3
PRINT. ,
LPRINT.
. lines 100, . .
4.
Turbo Pascal
program files4(input, output, myfile);
uses crt;
Var
Pinakas:array[1..50,1..50] of integer;
i,j,M,N:integer;
myfile:text;
begin
clrscr;
assign (myfile,ARXEIO.DAT);
reset (myfile);
278
{ }
readln (myfile, M, N);
for i:=1 to M do
begin
for j:=1 to N do
read(myfile,pinakas[i,j]);
readln (myfile);
end;
{ }
for i:=1 to M do
begin
for j:=1 to N do
write (pinakas[i,j], );
writeln
end;
readln;
end.
Quick Basic
DIM a(20, 20)
OPEN I, #1, data.dat
INPUT #1, m, n
FOR i = 1 TO m
FOR j = 1 TO n
INPUT #1, a(i, j)
NEXT j
NEXT i
CLOSE : END
a.
( )
.
( editor),
.
279
.
.
5.
Turbo Pascal
program files5(input, output, myfile);
uses crt;
const { }
N=4;
M=5;
Var
Pinakas:array[1..M,1..N] of integer;
i,j,MM,NN:integer;
myfile:text;
begin
assign (myfile,ARXEIO.DAT);
rewrite (myfile);
{ }
for i:=1 to M do
for j:=1 to N do
begin
write (PINAKAS[, I:2,,,J:2,]
readln(pinakas[i,j]);
end;
{ }
write(myfile,M:4,N:4);
for i:=1 to M do
begin
writeln(myfile);
for j:=1 to N do
write(myfile,pinakas[i,j]:5);
end;
);
280
close (myfile);
writeln ( );
readln
end.
Quick Basic
Save table
OPEN O,#1,"ARRAY.DAT"
PRINT #1,m,n
FOR i=1 TO m
FOR j=1 TO n
PRINT #1,a(i,j);
NEXT j
PRINT #1
NEXT i
CLOSE:RETURN