Monday, July 10, 2017

Uva problem solution 11520 - Fill the Square

problem link:


Discuss: In this problem you just simply start the loop from 65 and check the [i][j] th element's with adjacent element.if the adjacent element don't match then simply assign [i][j] element to the loop value.


try yourself before see the code



#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,j,cnt,t,k,jj;
    char sumi[11][11];
    cin >>t;
    for(k=1;k<=t;k++)
    {
        cin >>n;
        for(i=0;i<n;i++)
        {
            for(j=0;j<n;j++)
            {
                cin >>sumi[i][j];
            }
        }
        for(i=0;i<n;i++)
        {
            for(j=0;j<n;j++)
            {
                if(sumi[i][j]=='.')
                {
                    for(jj=65;jj<=91;jj++)
                    {
                        if(sumi[i][j+1]!=jj&&sumi[i][j-1]!=jj&&sumi[i+1][j]!=jj&&sumi[i-1][j]!=jj)
                        {
                             sumi[i][j]=jj;
                             break;
                        }

                    }
                }
            }
        }
        cout <<"Case "<<k<<':'<<endl;
       for(i=0;i<n;i++)
        {
            for(j=0; j < n ; j++)
            {
                cout <<sumi[i][j];
            }
            cout <<endl;
        }
    }
    return 0;
}

No comments:

Post a Comment