100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > 蓝桥杯:魔方旋转问题【高职组】

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

时间:2018-10-29 03:04:47

相关推荐

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

题目来源

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

按照题目的要求展开二阶魔方:

输入x时,顺时针移动带框的部分

输入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 }; //greenint Back[4] = {2,2,2,2 }; //blueint Up[4] = {3,3,3,3 }; //whiteint Down[4] = {4,4,4,4 }; //yellowint Left[4] = {5,5,5,5 };//orangeint Right[4] = {6,6,6,6 }; //redvoid 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;}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。