-
Notifications
You must be signed in to change notification settings - Fork 9
/
Rotating corner elements clockwise.c
71 lines (66 loc) · 1.13 KB
/
Rotating corner elements clockwise.c
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
#include<stdio.h>
#include <stdlib.h>
int main()
{
int m,n;
scanf("%d%d",&m,&n);
int a[m][n],i,j,k=0,b[n+m],temp;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if((i==0&&j==0)||(i==0&&j==n-1)||(i==m-1&&j==0)||(i==m-1&&j==n-1))
{
b[k]=a[i][j];
k++;
}
}
}
for(i=0;i<k;i++)
{
for(j=i+1;j<k;j++)
{
if(b[i]>b[j])
{
temp=b[i];
b[i]=b[j];
b[j]=temp;
}
}
}
int l=0;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if((i==0&&j==0)||(i==0&&j==n-1))
{
a[i][j]=b[l];
l++;
}
if((i==m-1&&j==0)||(i==m-1&&j==n-1))
{
a[i][j]=b[k-1];
k--;
}
printf("%d ",a[i][j]);
}
printf("\n");
}
}
input:
3 3
9 2 7
4 6 8
1 3 3
output:
1 2 3
4 6 8
7 3 9