Repository navigation
Expand file tree
/
Copy pathMatrixColumnRotation.PAS
More file actions
223 lines (211 loc) · 6.38 KB
/
Copy pathMatrixColumnRotation.PAS
File metadata and controls
223 lines (211 loc) · 6.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
Uses GRAPH, CRT;
Var dr, md, yntrvac, n, m : integer;
elq : boolean;
c : char;
Matric : Array [1..50, 1..50] of integer;
Const DOWN=#208; UP=#200; LEFT=#203; RIGHT=#205; ESC=#27; NULL=#0; ENTER=#13; SPACE=#32;
Mode : Array [1..4] of string[9] = ('Problem', 'Input', 'Solution', 'Exit');
Function GetKey : Char;
Var c : char;
Begin {GetKey}
c:=ReadKey;
Repeat
if c=NULL then
Begin c:=ReadKey;
if Ord(c)>127 then c:=NULL
else GetKey:=Chr(Ord(C)+128);
End
else GetKey:=c;
Until c<>NULL;
End; {GetKey}
Procedure Menu;
Begin
yntrvac:=1;
SetTextStyle(0, 0, 3);
SetColor(White);
SetFillStyle(1, Red);
Bar(220, 100, 420, 150);
OutTextXY(236, 112, 'Problem');
SetFillStyle(1, LightRed);
bar(220, 160, 420, 210);
outtextxy(260, 172, 'Input');
bar(220, 220, 420, 270);
outtextxy(224, 232, 'Solution');
bar(220, 280, 420, 330);
outtextxy(272, 292, 'Exit');
End;
Procedure problem;
Begin
SetColor(White); Settextstyle(0, 0, 1);
outtextxy(65, 170, ' Trvac NxM chapoxakanutyamb uxxankyun matricy, vori tarrery');
outtextxy(65, 185, 'amboxj tver en, grancel faylum yev artacel tesatipi ekrani');
outtextxy(65, 200, 'vra grafikakan rejimum.');
outtextxy(65, 215, ' Kazmel cragir, vory nuyn patkeri vra kcucadri matrici syuneri');
outtextxy(65, 230, 'texasharjy depi aj ciklik exanakov. Ptuyt@ dadarecnel kamayakan');
outtextxy(65, 245, 'stexn sexmeluc heto.');
GetKey;
End;
procedure inputdata;
var i, x : integer;
f : file of integer;
begin
Restorecrtmode;
Assign(f, 'input.txt'); Rewrite(f);
Readln(n, m);
write(f, n, m);
for i:=1 to n*m do
begin
read(x);
write(f, x);
end;
close(f);
setgraphmode(getgraphmode);
end;
procedure solution;
var i, j, yerkarutyun, pos, xx, yy : integer;
f : file of integer;
procedure syun(j, iMax, x, y : integer);
var i : integer;
s : string;
begin
SetFillStyle(1, White); settextstyle(0, 0, 1); setcolor(black);
if iMax<>n then
begin
bar(xx+x, yy+y+(iMax-1)*11, xx+x+yerkarutyun-1, yy+y+iMax*11-2);
str(matric[iMax][j], s);
outtextxy(xx+x+1, yy+y+(iMax-1)*11+1, s);
end
else
for i:=1 to iMax do
begin
bar(xx+x, yy+y+(i-1)*11, xx+x+yerkarutyun-1, yy+y+i*11-2);
str(matric[i][j], s);
outtextxy(xx+x+1, yy+y+(i-1)*11+1, s);
end;
end;
function amenayerkar : integer;
var i, j, max, min, y1, y2 : integer;
begin
max:=matric[1][1]; min:=matric[1][1];
for i:=1 to n do
for j:=1 to m do
begin
if matric[i][j]>max then max:=matric[i][j];
if matric[i][j]<min then min:=matric[i][j];
end;
y1:=0; y2:=0;
while max>0 do
begin
y1:=y1+1;
max:=max div 10;
end;
while min<0 do
begin
y2:=y2+1;
min:=min div 10;
end;
if y1>y2+1 then amenayerkar:=y1
else amenayerkar:=y2+1;
end;
procedure ptuyt;
var i, j, k : integer;
begin
for i:=1 to n do
begin
k:=matric[i][m];
for j:=m downto 2 do
matric[i][j]:=matric[i][j-1];
matric[i][1]:=k;
end;
end;
begin
assign(f, 'input.txt'); reset(f);
read(f, n, m);
for i:=1 to n do
for j:=1 to m do
read(f, matric[i][j]);
close(f);
yerkarutyun:=amenayerkar*8+2;
xx:=(GetMaxX - (yerkarutyun+1)*M) div 2;
yy:=(GetMaxY - 11*n) div 2;
for j:=1 to m do
syun(j, N, (j-1)*(yerkarutyun+1), 0);
c:=#0;
while not keypressed do
begin
for j:=m downto 1 do
begin
pos:=(j-1)*(yerkarutyun+1);
while pos<j*(yerkarutyun+1) do
begin
SetFillStyle(1, Green);
bar(xx+pos, yy, xx+pos+yerkarutyun, yy+n*11);
pos:=pos+1;
syun(j, N, pos, 0);
delay(50);
if keypressed then begin c:=getkey; break; end;
end;
if c<>#0 then break;
end;
if c<>#0 then break;
for i:=1 to N do
Begin
if KeyPressed then Begin C:=GetKey; Break; End;
syun(m, i, 0, 0);
Delay(1000);
End;
if c<>#0 then break;
delay(500);
SetFillStyle(1, Green);
bar(xx+m*(yerkarutyun+1), yy, xx+(m+1)*(yerkarutyun+1), yy+11*n);
ptuyt;
delay(500);
end;
GetKey;
end;
Begin {Main}
dr:=0;
InitGraph(dr, md, '');
SetFillStyle(1, Green);
Bar(0, 0, GetMaxX, GetMaxY);
Menu; elq:=false;
Repeat
c:=GetKey;
if (c=DOWN) and (yntrvac<4) then
Begin
SetFillStyle(1, LightRed);
Bar(220, 40+(yntrvac*60) , 420, 90+(yntrvac*60));
SetColor(White); SetTextStyle(0, 0, 3);
OutTExtXY(320-length(Mode[yntrvac])*12, 52+(yntrvac*60), Mode[yntrvac]);
yntrvac:=yntrvac+1;
SetFillStyle(1, Red);
Bar(220, 40+(yntrvac*60) , 420, 90+(yntrvac*60));
OutTExtXY(320-length(Mode[yntrvac])*12, 52+(yntrvac*60), Mode[yntrvac]);
End
else if (c=UP) and (yntrvac>1) then
Begin
SetFillStyle(1, LightRed);
Bar(220, 40+(yntrvac*60) , 420, 90+(yntrvac*60));
SetColor(White); SetTextStyle(0, 0, 3);
OutTExtXY(320-length(Mode[yntrvac])*12, 52+(yntrvac*60), Mode[yntrvac]);
yntrvac:=yntrvac-1;
SetFillStyle(1, Red);
Bar(220, 40+(yntrvac*60) , 420, 90+(yntrvac*60));
OutTExtXY(320-length(Mode[yntrvac])*12, 52+(yntrvac*60), Mode[yntrvac]);
End
else if c=ENTER then
Begin
SetFillStyle(1, Green);
Bar(0, 0, GetMaxX, GetMaxY);
case yntrvac of
1 : problem;
2 : inputdata;
3 : solution;
4 : elq:=true;
end;
SetFillStyle(1, Green);
Bar(0, 0, GetMaxX, GetMaxY);
Menu;
End;
Until elq;
End. {Main}