-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path00085.cpp
More file actions
46 lines (36 loc) · 1.08 KB
/
00085.cpp
File metadata and controls
46 lines (36 loc) · 1.08 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
// Problem: Eolymp 85 - Spiral
// Link: https://basecamp.eolymp.com/en/problems/85
#include <iostream>
#include <vector>
std::pair<int, int> findNumbers(int n, int i, int j) {
std::vector<std::vector<int>> matrix(n, std::vector<int>(n));
int num = 1;
int left = 0, right = n - 1, top = 0, bottom = n - 1;
while (num <= n * n) {
for (int k = left; k <= right; ++k) {
matrix[top][k] = num++;
}
top++;
for (int k = top; k <= bottom; ++k) {
matrix[k][right] = num++;
}
right--;
for (int k = right; k >= left; --k) {
matrix[bottom][k] = num++;
}
bottom--;
for (int k = bottom; k >= top; --k) {
matrix[k][left] = num++;
}
left++;
}
// Verilmiş koordinatlardakı ədədləri tapmaq
return std::make_pair(matrix[i - 1][j - 1], matrix[j - 1][i - 1]);
}
int main() {
int n, i, j;
std::cin >> n >> i >> j;
std::pair<int, int> result = findNumbers(n, i, j);
std::cout << result.first << std::endl;
return 0;
}