蓝桥杯:魔方旋转问题【高职组】

题目来源

比较容易的一题,但是要心细(写了好久)

按照题目的要求展开二阶魔方:
展开后输入x时,顺时针移动带框的部分
s
输入y和z同样移动相应部分。
有一点需注意:
e.g.当输入x时,绿色这一面需要顺时针翻转一下:
0 1 👉 2 0
2 3 👉 3 1
因为一面都是同一种颜色所以很容易被忽视

#include<iostream>
using namespace std;
int Front[4] = { 1,1,1,1 }; //green
int Back[4] = { 2,2,2,2 };  //blue
int Up[4] = { 3,3,3,3 };    //white
int Down[4] = { 4,4,4,4 };  //yellow
int Left[4] = { 5,5,5,5 };//orange
int Right[4] = { 6,6,6,6 }; //red
void Turn_x();
void Turn_y();
void Turn_z();
void output();
int main()
{
    string str;
    cin >> str;
    for (int i = 0; i < str.length(); i++)
    {
        if (str[i] == 'x') Turn_x();
        else if (str[i] == 'y')    Turn_y();
        else if (str[i] == 'z')    Turn_z();
    }
    output();
    return 0;
}
void output()
{
    int A[] = { Front[1],Right[0],Up[3] };
    for (int i = 0; i < 3; i++)
    {
        //string color="绿蓝白黄橙红";
        switch (A[i])
        {
        case 1:cout << "绿"; break;
        case 2:cout << "蓝"; break;
        case 3:cout << "白"; break;
        case 4:cout << "黄"; break;
        case 5:cout << "橙"; break;
        case 6:cout << "红"; break;
        }
    }
}
void Turn_x()
{
    int temp1, temp2, temp3, temp4, temp5, temp6;
    temp1 = Up[2], temp2 = Up[3];
    temp3 = Right[0], temp4 = Right[2];
    temp5 = Down[0], temp6 = Down[1];

    Up[2] = Left[1], Up[3] = Left[3];
    Right[0] = temp1, Right[2] = temp2;
    Down[0] = temp3, Down[1] = temp4;
    Left[1] = temp5, Left[3] = temp6;

    temp1 = Front[0], temp2 = Front[1], temp3 = Front[2], temp4 = Front[3];
    Front[0] = temp3, Front[1] = temp1, Front[2] = temp4, Front[3] = temp2;
}
void Turn_y()
{
    int temp1, temp2, temp3, temp4, temp5, temp6;
    temp1 = Up[1], temp2 = Up[3];
    temp3 = Back[1], temp4 = Back[3];
    temp5 = Down[1], temp6 = Down[3];

    Up[1] = Front[1], Up[3] = Front[3];
    Back[1] = temp1, Back[3] = temp2;
    Down[1] = temp3, Down[3] = temp4;
    Front[1] = temp5, Front[3] = temp6;

    temp1 = Right[0], temp2 = Right[1], temp3 = Right[2], temp4 = Right[3];
    Right[0] = temp3, Right[1] = temp1, Right[2] = temp4, Right[3] = temp2;
}
void Turn_z()
{
    int temp1, temp2, temp3, temp4, temp5, temp6;
    temp1 = Left[0], temp2 = Left[1];
    temp3 = Back[2], temp4 = Back[3];
    temp5 = Right[0], temp6 = Right[1];

    Left[0] = Front[0], Left[1] = Front[1];
    Back[2] = temp1, Back[3] = temp2;
    Right[0] = temp3, Right[1] = temp4;
    Front[0] = temp5, Front[1] = temp6;

    temp1 = Up[0], temp2 = Up[1], temp3 = Up[2], temp4 = Up[3];
    Up[0] = temp3, Up[1] = temp1, Up[2] = temp4, Up[3] = temp2;
}

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值