-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodeup 1476.cpp
More file actions
84 lines (79 loc) · 1.12 KB
/
codeup 1476.cpp
File metadata and controls
84 lines (79 loc) · 1.12 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
#include <iostream>
#include <algorithm>
#define X_Pos 101
#define Y_Pos 101
long long int arr[X_Pos][Y_Pos];
int main()
{
long long int n, m;
long long int count = 1;
std::cin >> n >> m;
int k = 1;
int x, y;
if (n < m)
{
for (int i = 0; i < n; i++)
{
x = 0;
for (int j = 0; j <= i; j++)
{
if (i + x >= 0 && j >= 0)
{
arr[i + x][j] = count;
x--;
count++;
}
}
}
for (int d = 1; d < m; d++)
{
y = 0;
for (int j = d; j < m; j++)
{
if (n - 1 - y >= 0 && d + y >= 0)
{
arr[(n - 1) - y][d + y] = count;
count++;
y++;
}
}
}
}
else
{
for (int i = 0; i < n; i++)
{
x = 0;
for (int j = 0; j < m; j++)
{
if (i + x >= 0)
{
arr[i + x][j] = count;
x--;
count++;
}
}
}
for (int d = 1; d < m; d++)
{
y = 0;
for (int j = d; j < m; j++)
{
if (n - 1 - y >= 0 && d + y >= 0)
{
arr[(n - 1) - y][d + y] = count;
count++;
y++;
}
}
}
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
std::cout << arr[i][j] << " ";
}
std::cout << std::endl;
}
}