CHCUBE - Editorial

Unfortunately there are a number of things wrong with your code. Probably the most confusing one for you is that the example test cases don’t work. The following code is incorrect. You need to account for the null terminator at the end of the string (\0).

char color_array[6],first_color[6],second_color[6];

This is causing the testcases variable to be overwritten with a zero. So when I tried to run the two example test cases your code stopped after the first one.

The second issue is that you only sometimes print out a “YES” or “NO” every line test case needs a yes or no.

Also your logic is incorrect. It’s not enough to check there are three or less colours. The following two test cases have less than three colours but both should give NO as the correct answer.

2

blue blue green green blue black

blue blue green green blue blue

You need to check that the adjacent faces are the same colour.

Have a look at my answer. CodeChef: Practical coding for everyone If the front is one colour then the top and one side need to be the same colour or the bottom and one side need to be the same colour. If this is true then print YES. The same for back.

Hi articblue, Thank you for your reponse… How about this one… CodeChef: Practical coding for everyone This runs fine for the two testcases that you gave. I understand the null terminator issue but isn’t the logic correct for this one? What you have said I have tried to program the same logic i.e

“If the front is one colour then the top and one side need to be the same colour or the bottom and one side need to be the same colour. If this is true then print YES. The same for back.”

Try:

1

blue blue orange blue blue orange

You code gives NO when the correct answer is YES.

Thanks for that. I got the problem. Thanks very much again :slight_smile:

I am getting WA. please tell me the mistake.
#include <bits/stdc++.h>
using namespace std;

int main() {

int t;
cin>>t;
while(t--)
{
    string s[6];
    int i,j,co=0,c1=0,flag=0;
    for(i=0;i<6;i++)
    {
        cin>>s[i];
    }
    for(i=0;i<6;i+=2)
    {
        if(!s[i].compare(s[i+1]))
        c1++;
    }
     for(i=0;i<6;i+=1)
    {  if(i+1<6)
    {
        if(!s[i].compare(s[i+1]))
        flag++;
    }
    }
   for(i=0;i<6;i++)
   {
       for(j=i+1;j<6;j++)
        { 
            if(!s[i].compare(s[j]))
       {
           co++;
        }
            
        }
    }
    if(co>=3)
    {
    if(c1>2 && flag==5)
    cout<<"YES"<<endl;
   else if(c1<2)
    cout<<"YES"<<endl;
    else
    cout<<"NO"<<endl;
    }
    else
    cout<<"NO"<<endl;
}
return 0;

}