-
Notifications
You must be signed in to change notification settings - Fork 0
/
lab1.cpp
60 lines (53 loc) · 1.19 KB
/
lab1.cpp
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
#include <iostream>
#include <fstream>
#include <time.h>
#define n 500 //размер решетки
#define m 3 //число дислокаций
using namespace std;
//генерация рандомных чисел
int random(int k) {
float f = (rand() % n);
return f;
}
int main()
{
srand(time(NULL));
ofstream outf("task1.txt", ios::app);
int A[n][n];
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
A[i][j] = 1;
}
}
int x = random(n);
int y = random(n);
A[x][y] = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
cout << A[i][j];
}
cout << "\n";
}
bool end = 0;
for (int step = 0; !end; ++step) {
if ((x == 0) || (x == n - 1) || (y == 0) || (y == n - 1)) {
outf << n << " " << step << "\n";
end = 1;
}
else {
int v = random(4);
if (v == 0) {
x++;
}
if (v == 1) {
x--;
}
if (v == 2) {
y++;
}
if (v == 3) {
y--;
}
}
}
}