cube painting

将六个面分别遍历查看是否有另一个正方体一致,分别写出上下翻转和左右翻转的方法,可以得到44的结果,然后将两个侧面未遍历的利用上下和左右的方法翻转到,然后遍历可得到24的结果,编写检验是否一致的方法,可以ac

#include 
#include 
using namespace std;
char c1[7];
char c2[7];
void hturn()
{
    char temp = c2[1];
    c2[1] = c2[5];
    c2[5] = c2[6];
    c2[6] = c2[2];
    c2[2] = temp;
}
void vturn()
{
    char temp = c2[2];
    c2[2] = c2[3];
    c2[3] = c2[5];
    c2[5] = c2[4];
    c2[4] = temp;
}
int cjudge()
{

    for(int i = 1; i <=6; ++i)
    {
        if(c1[i] != c2[i])
        {
            return 0;
        }
    }
    return 1;
}

int main()
{

    //freopen("data.out", "w", stdout);
    char str[12];
    while(scanf("%s", str) != EOF)
    {
        bool flag = false;
        for(int i = 0; i < 6; ++i)
        {
        c1[i+1] = str[i];
        }
        for(int i = 6; i < 12; ++i)
        {
            c2[i-5] = str[i];
        }
        for(int i = 0; i < 4; ++i)
        {
            hturn();
            for(int j = 0; j < 4; ++j)
            {
                vturn();
                if(cjudge())
                {
                    //cout << "TRUE" << endl;
                    //printf("%s\n", "TRUE");
                    flag = true;
                    break;
                }

            }
            if(flag == true)
            {
                break;
            }

        }
        vturn();
        hturn();
        for(int i = 0; i < 4; ++i)
        {
            vturn();
            if(cjudge())
            {
                //printf("%s\n", "TRUE");
                flag = true;
                break;
            }

        }
        hturn();
        hturn();
        for(int i = 0; i < 4; ++i)
        {
            vturn();
            if(cjudge())
            {
               // printf("%s\n", "TRUE");
                flag = true;
                break;
            }
        }
        if(flag == false)
        {
            printf("%s\n", "FALSE");
            //cout << "FALSE" << endl;
        }
        else
        {
            printf("%s\n", "TRUE");
        }
    }

    return 0;
}

建议找个正方体的盒子自己试一试,可以很快得到灵感。

你可能感兴趣的:(算法入门经典)