-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathP44649.cpp
66 lines (58 loc) · 1.47 KB
/
P44649.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
61
62
63
64
65
66
// P44649 F012A. La vaca miop
// Created by arnxxau on 14/01/2022.
//
#include <iostream>
#include <vector>
using namespace std;
typedef vector<vector<char> > field;
field create_field(const int& wall_size, const int& s_pos, const int& cow_pos) {
field f (wall_size, vector<char>(100, '.'));
for (int i = 0; i < wall_size; ++i) {
f[i][0] = '|';
}
f[s_pos][0] = '=';
f[cow_pos][1] = 'V';
return f;
}
void mark_field(field& f, int& i, int& j, const int& move, const int& s_pos) {
int n = move;
if (move > 0) {
while (n != 0 and i != s_pos) {
++i; ++j;
f[i][j] = 'V';
--n;
}
} else {
while (n != 0 and i != s_pos) {
--i; ++j;
f[i][j] = 'V';
++n;
}
}
}
void print_field(const field& f, const int& limit) {
int f_size = f.size();
for (int i = 0; i < f_size; ++i) {
for (int j = 0; j < limit; ++j) {
cout << f[i][j];
}
cout << endl;
}
}
field move_cow(field& f, const int& s_pos, int& cow_pos, int& j) {
int to_move = 1;
while (cow_pos != s_pos) {
mark_field(f, cow_pos, j, to_move, s_pos);
to_move *= -2;
}
f[s_pos][++j] = 'V';
return f;
}
int main() {
int wall_size, s_pos, cow_pos;
cin >> wall_size >> s_pos >> cow_pos;
field f = create_field(wall_size, s_pos, cow_pos);
int j = 1;
move_cow(f, s_pos, cow_pos, j);
print_field(f, j);
}