-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatrix rotation.cpp
96 lines (85 loc) · 1.21 KB
/
matrix rotation.cpp
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
87
88
89
90
91
92
93
94
95
96
#include <iostream>
using namespace std;
int main()
{
int m,n,r;
cin>>m>>n>>r;
int a[m][n];
for(int i=1;i<=m;i++)
for(int j=1;j<=n;j++)
{
cin>>a[i][j];
}
int fla=0,fla2=0;
int no=min(m,n);
no=no/2;
int i=1,j=1;
int orgm=m,orgn=n;
int number=r*no;
int count1=1,count2=1;
int orgno=no;
while(r>0)
{
swap(a[count1][count2],a[i][j]);
cout<<endl<<i<<" "<<j<<" "<<count1<<" "<<count2<<" "<<a[count1][count2]<<" "<<fla<<" "<<fla2<<endl;
for(int opo=1;opo<=orgm;opo++)
{
for(int opp=1;opp<=orgn;opp++)
{
cout<<a[opo][opp]<<" ";
}
cout<<endl;
}
if(i<m && j<=n && fla==0)
{
cout<<" bush "<<endl;
i++;
}
else if(j<n && i<=m && fla2==0)
{
j++;
fla=1;
}
else if(i<=m && j==n && i>1)
{
i--;
fla2=1;
}
else if(j>1)
{
j--;
}
else
{
cout<<endl<<" uyyyyyyyyyyyyyyyyyyyyy"<<endl;
i=1;
j=1;
fla=0;
fla2=0;
r--;
number--;
if(r==0&&number>0)
{
count1++;
count2++;
m--;
n--;
i=count1;
j=count2;
r=orgno;
}
}
}
for(int i=1;i<=orgm;i++)
{
for(int j=1;j<=orgn;j++)
{
cout<<a[i][j]<<" ";
}
cout<<endl;
}
/*int firstElement;
while(no>1)
{
}*/
}