1333A. Little Artem - Codeforces Solution C++

  Problem Link : 1333A. Little Artem 


✅ C++ Solution :

 
#include<bits/stdc++.h>
using namespace std;

#define ll long long int
#define pb push_back
#define mp make_pair

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,m;
		cin>>n>>m;

		int k=n*m;
		int w=k/2;
		int b=w+1;

		char arr[n][m];

        if(n%2!=0 && m%2!=0)
        {


            for(int i=0;i<n;i++)
            {

                if(i%2==0)
                {

                    for(int j=0;j<m;j++)
                    {

                        if(j%2==0)
                            arr[i][j]='B';
                        else
                            arr[i][j]='W';
                    }
                }
                else{

                    for(int j=0;j<m;j++)
                    {

                        if(j%2==0)
                            arr[i][j]='W';
                        else
                            arr[i][j]='B';
                    }
                }
            }
        }
        else{
            for(int i=0;i<n;i++)
            {
                if(i==n-1)
                {
                     if(i%2==0)
                {

                    for(int j=0;j<m;j++)
                    {

                        if(j%2==0 || j+2>=m)
                            arr[i][j]='B';
                        else
                            arr[i][j]='W';
                    }
                }
                else{

                    for(int j=0;j<m;j++)
                    {

                        if(j%2==0 && j+2<m)
                            arr[i][j]='W';
                        else
                            arr[i][j]='B';
                    }
                }

                }
                else{
                if(i%2==0)
                {

                    for(int j=0;j<m;j++)
                    {

                        if(j%2==0)
                            arr[i][j]='B';
                        else
                            arr[i][j]='W';
                    }
                }
                else{

                    for(int j=0;j<m;j++)
                    {

                        if(j%2==0)
                            arr[i][j]='W';
                        else
                            arr[i][j]='B';
                    }
                }
                }
            }


        }
        for(int i=0;i<n;i++)
        {

            for(int j=0;j<m;j++)
                cout<<arr[i][j];
            cout<<endl;
        }




	}
}

 

Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook. 

😇Happy Learning!!