View difference between Paste ID: TJuH5RJg and 9m2yWyBd
SHOW: | | - or go back to the newest paste.
1
#include <iostream>
2
#include <vector>
3
#include <utility>
4
5
class Index
6
{
7
    int x, y, x_max, y_max;
8
9
public:
10
    Index(int x, int y, int x_max, int y_max) : x(x), y(y), x_max(x_max-1), y_max(y_max-1) {}
11
12
    void moveIndex();
13
    int getX()
14
    {
15
        return x;
16
    }
17
    int getY()
18
    {
19
        return y;
20
    }
21
};
22
23
void Index::moveIndex()
24
{
25
    if( x == 0 )
26
    {
27
        if ( y < y_max )
28
        {
29
            y++;
30
            return;
31
        }
32
33
        else if ( y == y_max )
34
        {
35
            x++;
36
            return;
37
        }
38
    }
39
40
    else if( x == x_max )
41
    {
42
        if ( y > 0 )
43
        {
44
            y--;
45
            return;
46
        }
47
48
        if ( y == 0 )
49
        {
50
            x--;
51
            return;
52
        }
53
    }
54
55
    else
56
    {
57
        if ( y == y_max )
58
        {
59
            x++;
60
            return;
61
        }
62
        if ( y == 0 )
63
        {
64
            x--;
65
            return;
66
        }
67
    }
68
}
69
70-
/*
70+
71-
00 01 02
71+
72-
10 11 12
72+
73-
20 21 22
73+
74
        v.push_back( std::vector<int>(columns) );
75-
1 2 3
75+
76-
4 5 6
76+
77-
7 8 9
77+
78
void writeArray(std::vector<std::vector<int>> arr)
79-
2 3 6
79+
80-
1 5 9
80+
81-
4 7 8
81+
82
        for(auto y : x)
83-
0 1 2
83+
84-
1 1 2
84+
85-
2 2 2
85+
86
}
87-
00 01 02
87+
88-
10 11 12
88+
89-
20 21 22
89+
90
    int steps = 2 * (rows-1) + (2 * (columns-1)) - 1;
91-
0,0 > 0,1 1
91+
92-
0,1 > 0,2 2
92+
93-
0,2 > 1,2 3
93+
94-
1,2 > 2,2 4
94+
95-
2,2 > 2,1 5
95+
96-
2,1 > 2,0 6
96+
97-
2,0 > 1,0 7
97+
98
}
99-
for(int i = 0; i < x.size(); i++)
99+
100-
    for(int j = 0; j < x.size(); j++)
100+
101
{
102-
0 1 2 3
102+
103-
1 1 2 3
103+
104-
2 2 2 3
104+
105-
3 3 3 3
105+
106
        std::cin>>l>>k;
107-
0,0 > 0,1 1
107+
108-
0,1 > 0,2 2
108+
109-
0,2 > 0,3 3
109+
110-
0,3 > 1,3 4
110+
111-
1,3 > 2,3 5
111+
112-
2,3 > 3,3 6
112+
113-
3,3 > 3,2 7
113+
114-
3,2 > 3,1 8
114+
115-
3,1 > 3,0 9
115+
116-
3,0 > 2,0 10
116+
117-
2,0 > 1,0 11
117+