-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBeautiful_Matrix.cpp
More file actions
53 lines (52 loc) · 1.19 KB
/
Copy pathBeautiful_Matrix.cpp
File metadata and controls
53 lines (52 loc) · 1.19 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
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main(){
int a[5][5];
int i,j;
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
cin>>a[i][j];
}
}
int count=0;
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(a[i][j]==1){
if(j>2){
count++;
int t = a[i][j];
a[i][j] = a[i][j-1];
a[i][j-1] = t;
j=0;
}
else if(j<2){
count++;
int t = a[i][j];
a[i][j] = a[i][j+1];
a[i][j+1] = t;
j=0;
}
else if(i>2){
count++;
int t = a[i][j];
a[i][j] = a[i-1][j];
a[i-1][j] = t;
i=0;
}
else if(i<2){
count++;
int t = a[i][j];
a[i][j] = a[i+1][j];
a[i+1][j] = t;
i=0;
}
}
}
}
cout<<count;
}