-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdiagonal_sort.cpp
More file actions
73 lines (57 loc) · 874 Bytes
/
diagonal_sort.cpp
File metadata and controls
73 lines (57 loc) · 874 Bytes
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
#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector<vector< int >> mat{{3,3,1,1},{2,2,1,2},{1,1,1,2}};
int m = mat.size(), n = mat[0].size();
printf("%d %d \n",m, n );
for(int i=0; i<n; i++)
{
std::vector<int> d;
int c = i;
for(int j=0; j<m; j++)
{
d.push_back(mat[j][c]);
c+=1;
if(c>=n)
break;
}
sort(d.begin(), d.end());
c = i;
for(int j=0; j<m; j++)
{
mat[j][c] = d[j];
c+=1;
if(c>=n)
break;
}
}
for(int i=1; i<m; i++)
{
std::vector<int> d;
int c = i;
for(int j=0; j<n; j++)
{
d.push_back(mat[c][j]);
c+=1;
if(c>=m)
break;
}
sort(d.begin(), d.end());
c = i;
for(int j=0; j<n; j++)
{
mat[c][j] = d[j];
c+=1;
if(c>=m)
break;
}
}
for(int i=0; i<m; i++)
{
for(int j=0; j<n; j++)
printf("%d ", mat[i][j]);
printf("\n");
}
}