【水模拟】#35 A.Shell Game

A. Shell Game
time limit per test
2 seconds
memory limit per test
64 megabytes
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 test(s)
input
1
1 2
2 1
2 1
output
2
input
1
2 1
3 1
1 3
output
2


我居然第12次才AC…… 简直不高兴…… 首先是不知道要文件输入输出……

然后就是各种RE……一怒之下就不用数组了——

 Code:

#include <cmath>   
#include <cstdio>  
#include <string>  
#include <cstring>  
#include <iostream>  
#include <algorithm>
using namespace std;

int main()
{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	
	int ball,n=3;
	int a,b;
	cin>>ball;
	while(n--)
	{
		cin>>a>>b;
		ball= a==ball?b:b==ball?a:ball;
	} 
	cout<<ball;
/* 
	int n,ball[5];
	scanf("%d",&n);
	ball[n]=1;
	for(int i=1;i<=3;i++)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		if(ball[a]+ball[b]==0);
		else
		{
			ball[a]=1-ball[a];
			ball[b]=1-ball[b];
		}
	}
	for(int j=1;j<=3;j++)	if(ball[j]==1) printf("%I64d",(__int64)j); 
*/ 
	fclose(stdin);
	fclose(stdout);
	return 0;
}



编写一个简单的Shell脚本来模拟贪吃蛇游戏可能会涉及到一些基本的控制结构、输入处理和循环。这里提供一个基础版的思路: ```bash #!/bin/bash # 定义屏幕大小和初始位置 rows=20 cols=40 snake=(5 5) # 起点坐标 food=$((rows / 2)) $(cols - 1) # 食物的位置,设置在右下角 while true; do clear # 清空屏幕 for ((i=0; i<${#snake[@]}; i++)); do echo "O" "${snake[i]}" # 使用'O'表示蛇的身体部分,打印蛇的位置 done echo "|" $((${snake} + 1)) ${snake} "| Food" $((${food} + 1)) ${food} "|" # 同样地,显示食物的位置 read -p "Press any key to move (w/a/s/d or q to quit): " direction # 获取用户输入 case $direction in w) if [[ ${snake} -gt 1 ]]; then snake=(${snake} ${snake} -1) fi ;; a) if [[ ${snake} -gt 1 ]]; then snake=(-1 ${snake}) fi ;; s) if [[ ${snake} -lt $((rows - 2)) ]]; then snake=(${snake} ${snake} + 1) fi ;; d) if [[ ${snake} -lt $((cols - 2)) ]]; then snake=(${snake} + 1) fi ;; q) echo "Game Over" exit ;; *) echo "Invalid input" ;; esac # 检查蛇是否吃到食物 if [ ${snake} == ${food} ] && [ ${snake} == ${food} ]; then food=$((random % rows)) $(random % cols) # 食物随机移动到新位置 let "snake+=1" "snake+=1" # 如果蛇吃到食物,长度加一 else # 检查蛇是否撞墙或自身 if [ ${snake} -lt 0 ] || [ ${snake} -gt $(($cols - 1)) ] || \ [ ${snake} -lt 0 ] || [ ${snake} -gt $(($rows - 1)) ]; then echo "Game Over" exit fi last_pos="${snake} ${snake}" snake=(("${snake[@]:0:1}") "${snake[@]:2}") if [[ ${snake[@]} =~ ${last_pos} ]]; then echo "Game Over" exit fi fi done ``` 这个脚本只是一个基本框架,实际的游戏逻辑还有许多细节需要完善,比如碰撞检测、得分管理等。运行此脚本前,请确保你的系统支持`clear`命令。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

糖果天王

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值