Shell Game

55 篇文章 0 订阅
22 篇文章 0 订阅

Description
input
input.txt
output
output.txt
Today the «Z» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then he openly puts a small ball under one of the cups and starts to shuffle the cups around very quickly so that on the whole he makes exactly 3 shuffles. After that the spectators have exactly one attempt to guess in which cup they think the ball is and if the answer is correct they get a prize. Maybe you can try to find the ball too?

Input
The first input line contains an integer from 1 to 3 — index of the cup which covers the ball before the shuffles. The following three lines describe the shuffles. Each description of a shuffle contains two distinct integers from 1 to 3 — indexes of the cups which the performer shuffled this time. The cups are numbered from left to right and are renumbered after each shuffle from left to right again. In other words, the cup on the left always has index 1, the one in the middle — index 2 and the one on the right — index 3.

Output
In the first line output an integer from 1 to 3 — index of the cup which will have the ball after all the shuffles.

Sample Input
Input
1
1 2
2 1
2 1
Output
2
Input
1
2 1
3 1
1 3
Output
2
题目是给你三个杯子,倒扣,在一个下面放一个球,在几次变换之后看最后球在哪个位置。
代码

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int main()
{
    int n, x, y, a[10];
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    while(~scanf("%d", &n))
    {
        for(int i = 1; i <= 3; i++)
            a[i] = i;
        for(int i = 0; i < 3; i++)
        {
            scanf("%d %d", &x, &y);
            swap(a[x], a[y]);
        }
        printf("%d\n", a[n]);
    }
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值