MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / main

Function main

Codeforces_problems/Beautiful Matrix/solution.cpp:3–29  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1#include<bits/stdc++.h>
2using namespace std;
3int main()
4 {
5 /* In this problem we basically need to find the position of the 1 in the 5 x 5 matrix
6 which is only present once in the matrix and then we need to find the absolute difference
7 of the index of the element present in the middle (which is always (2,2) in the 5 x 5 matrix)
8 with the one which has element "1" in it */
9
10 int num,i,j; // Taking "n" for the input of the element (which is either 1 or 0) , i and j are for iterating into the matrix
11 int row, col; // row and col is for storing the indices of the row and column of the matrix which has 1 in it
12
13 // Now iterating through the input 5 x 5 matrix
14 for(i=0;i<5;i++) // i is for iterating through rows
15 {
16 for(j=0;j<5;j++) // j is for iterating through columns
17 {
18 cin>>num; // Taking num as the input of all the elements of 5 x 5 matrix
19 if(num==1) // if num==1
20 {
21 row=i; // storing the position of the element
22 col=j; // of the matrix which has 1 in it.
23 }
24 }
25 }
26 // Simply printing the sum of the absolute difference of the position of the element "1" of the matrix with the position of the middle element i.e.,abs(row-2)+abs(col-2)
27 cout<<abs(row-2)+abs(col-2)<<endl;
28
29 }

Callers

nothing calls this directly

Calls 1

absFunction · 0.85

Tested by

no test coverage detected