263A. Beautiful Matrix
Problem Link: https://codeforces.com/problemset/problem/263/A
Solution 1:
import java.util.*;
public class A263 {
public static Scanner scn = new Scanner(System.in);
public static void input(int[][] arr) {
for (int i = 0; i < 5; i++)
for (int j = 0; j < 5; j++)
arr[i][j] = scn.nextInt();
}
public static int TotalMoves(int[][] arr) {
boolean flag = true;
int x = 0, y = 0;
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
if (arr[i][j] == 1) {
x = i;
y = j;
flag = false;
break;
}
}
if (!flag)
break;
}
return Math.abs(3-(x+1))+Math.abs(3-(y+1));
}
public static void main(String[] argv){
int[][] arr = new int[5][5];
input(arr);
System.out.println(TotalMoves(arr));
}
}
No comments:
Post a Comment
Thanks