Sunday, May 30, 2021

codeforces 263A Solution A. Beautiful Matrix (codeforces 263A) (rank 800*)

 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 = 0i < 5i++)
            for (int j = 0j < 5j++)
                arr[i][j] = scn.nextInt();
    }

    public static int TotalMoves(int[][] arr) {
        boolean flag = true;
        int x = 0y = 0;
        for (int i = 0i < 5i++) {
            for (int j = 0j < 5j++) {
                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

Climate Crisis and Innovation: Navigating Earth's Future

Climate Change: Recent Events and Technological Solutions 1. The Escalating Climate Crisis The climate crisis has intensified in recent year...