Special Matrix - Hackerearth

C++ 14 Solution

    #include<iostream>
    using namespace std;
    int main()
    {
         int t ;
         cin>>t;
            while(t!=0)
            {
                int n;
                cin>>n;
                int mid = n/2+1;
                char ar[n+1][n+1];
                int i, j, k, l;
                for(i=1;i<=n;i++)
                {
                    for(j=1;j<=n;j++)
                    {
                        cin>>ar[i][j];
                        if(ar[i][j]=='*')
                        {
                            k=i;
                            l=j;
                        }
                    }
                }
                cout<<abs(mid-k)+abs(mid-l)<<endl;
                t--;
            }
        return 0;
    } 

 

Click this link to try it on Hackerearth




Comments

Popular posts from this blog

First Unique Character in a String

Balanced Binary Tree

Majority Element

Sequential Digits