So I was trying to solve uva 11959 Dice. But the third example the question gave give me the wrong answer. Then I found out if I change
cin >> d1 >> d2;
to
scanf("%lx %lx", &d1, &d2);
and it works but I don't know why. However when I submit my code it shows that my answer is wrong. Can anyone help me with both questions?
My code:
#include <iostream>
#include <cstdio>
using namespace std;
//rotate and flip the dice
#define R(d) ( ((d) & 0x000F00) << 12 | ((d) & 0x00000F) << 16 | ((d) & 0x00F0F0)
| ((d) & 0x0F0000) >> 8 | ((d) & 0xF00000) >> 20 )
#define F(d) (((d) & 0x000F0F) | ((d) & 0x00F000) << 8 | ((d) & 0x0000F0) << 12
| ((d) & 0x0F0000) >> 4 | ((d) & 0xF00000) >> 16)
bool E(long d1, long d2)
{
return ( (d1) == (d2) || (d1) == R(d2) || (d1) == R(R(d2)) || (d1) == R(R(R(d2))) );
}
int main()
{
long d1, d2;
long counter;
bool equal;
cin >> counter;
for( int i = 0 ; i < counter ; i++ )
{
scanf("%lx %lx", &d1, &d2);
// cin >> d1 >> d2;
equal = E(d1, d2) || E(d1, F(d2)) || E(d1, F(F(d2)))
|| E(d1,F(F(F(d2)))) ;
if(equal)
cout << "Equal";
else
cout << "Not Equal";
cout << endl;
}
return 0;
}
ADD: I found out in my for loop I need to add two more condition to determine "equal". So it should looks like this:
equal = E(d1, d2) || E(d1, F(d2)) || E(d1, F(F(d2))) || E(d1, F(F(F(d2)))) || E(d1, F(R(d2))) || E(d1, F(R(R(R(d2)))));
But I still dont know why I need to add these two conditions. Isn't it already been covered?