题目描述
Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess the current position of the ball.
Bomboslav noticed that guys are not very inventive, so the operator always swaps the left shell with the middle one during odd moves (first, third, fifth, etc.) and always swaps the middle shell with the right one during even moves (second, fourth, etc.).
Let’s number shells from 00 to 22 from left to right. Thus the left shell is assigned number 00 , the middle shell is 11 and the right shell is 22 . Bomboslav has missed the moment when the ball was placed beneath the shell, but he knows that exactly nn movements were made by the operator and the ball was under shell xx at the end. Now he wonders, what was the initial position of the ball?
输入格式
The first line of the input contains an integer nn (1<=n<=2·10^{9}1<=n<=2⋅10次方9 ) — the number of movements made by the operator.
The second line contains a single integer xx ( 0<=x<=2 0<=x<=2 ) — the index of the shell where the ball was found after nn movements.
输出格式
Print one integer from 0 to 2 — the index of the shell where the ball was initially placed //initially是adj初始的
题目解答
注意:这是6个一轮回,英语读明白,看看啥意思。swtich注意有break;deault
switch用法:
switch(expression){
case constant-expression :
statement(s);
break; // 可选的
case constant-expression :
statement(s);
break; // 可选的
// 您可以有任意数量的 case 语句
default : // 可选的
statement(s);
}
AC代码如下:
using namespace std;
#include <iostream>
#include <cstring>
/*
0次 012
1次 102
2次 120
3次 210
4次 201
5次 021
6次 012
*/
int main ()
{
unsigned long long int n;
int aa;
cin>>n>>aa;
char a[4];
switch (n%6)
{
case 0: strcpy(a,"012"); break;
case 1: strcpy(a,"102"); break;
case 2: strcpy(a,"120"); break;
case 3: strcpy(a,"210"); break;
case 4: strcpy(a,"201"); break;
case 5: strcpy(a,"021"); break;
}
cout<<a[aa];
/*if(a[0]-'0'==aa)
{
cout<<'0';
}
if(a[1]-'0'==aa)
{
cout<<'1';
}
if(a[2]-'0'==aa)
{
cout<<'2';
}*/
return 0;
}