-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpiral_form.cpp
More file actions
86 lines (74 loc) · 2.08 KB
/
Copy pathSpiral_form.cpp
File metadata and controls
86 lines (74 loc) · 2.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
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
85
86
#include <iostream>
int main()
{
int t;
std::cin >> t;
while (t--)
{
int row, col;
std::cin >> row >> col;
int x = row, y = col;
int a[row + 5][col + 5];
for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j++)
{
std::cin >> a[i][j];
}
}
int tmpRow = 0, tmpCol = 0;
int prev, curr;
while (tmpRow < row && tmpCol < col)
{
if(tmpRow + 1 == row || tmpCol+1 == col)
break;
prev = a[tmpRow+1][tmpCol];
for (int i = tmpCol; i < col; i++)
{
//std::cout << a[tmpRow][i] << " ";
curr = a[tmpRow][i];
a[tmpRow][i]=prev;
prev = curr;
}
tmpRow++;
for (int i = tmpRow; i < row; i++)
{
//std::cout << a[i][col - 1] << " ";
curr = a[i][col-1];
a[i][col-1] = prev;
prev = curr;
}
col--;
if (tmpRow < row)
{
for (int i = col - 1; i >= tmpCol; i--)
{
//std::cout << a[row - 1][i] << " ";
curr = a[row-1][i];
a[row-1][i] = prev;
prev = curr;
}
row--;
}
if (tmpCol < col)
{
for (int i = row - 1; i >= tmpRow; i--)
{
//std::cout << a[i][tmpCol] << " ";
curr = a[i][tmpCol];
a[i][tmpCol] = prev;
prev = curr;
}
tmpCol++;
}
}
for (int i = 0; i < x; i++)
{
for (int j = 0; j < y; j++)
{
std::cout<<a[i][j]<<" ";
}
}
std::cout << std::endl;
}
}