-
Notifications
You must be signed in to change notification settings - Fork 138
/
Beautiful_Matrix.java
60 lines (60 loc) · 1.33 KB
/
Beautiful_Matrix.java
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
import java.util.*;
public class Beautiful_Matrix {
static Scanner sr = new Scanner(System.in);
public static void main(String args[])
{
int i=0,j=0,row=0,col=0,count=0;
int arr[][] = new int[5][5];
String str = null;
String[] a = new String[5];
for(i=0;i<5;i++)
{
str = sr.nextLine();
str.trim();
a = str.split(" ");
for(j=0;j<5;j++)
{
arr[i][j] = Integer.parseInt(a[j]);
}
}
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(arr[i][j] == 1)
{
row = i+1;
col = j+1;
break;
}
}
}
while(row!=3)
{
if(row>3)
{
row--;
count++;
}
else
{
row++;
count++;
}
}
while(col!=3)
{
if(col>3)
{
col--;
count++;
}
else
{
col++;
count++;
}
}
System.out.println(count);
}
}