跳到正文

个人记录

疯狂9选1

wuweize150815约 1 分钟
原文
文章信息与版本

文章信息

收录
2026年7月16日
更新
2026年7月16日
篇幅
约 1 分钟

版本

  1. v1当前
C++
#include <bits/stdc++.h>
#include <windows.h>
using namespace std;
int s[10]; 
int cnt=0;
int main ( )
{
	srand (time (0));
	cout << "抽奖游戏正式开始:\n";
	while (1)
	{ 
		Sleep (400);
		memset (s , 0 , sizeof (s));
		for (int i=1;i<=8);i++)
		{
			while (1)
			{
				int x=rand ( )%9+1;
				if (s[x]==0)
				{
					s[x]=1;
					break;
				} 
			}
		}
		cout << "1 2 3\n4 5 6\n7 8 9\n\n你要选哪个?\n\n";
		int k;
		cin >> k;
		if (s[k]==1)
		{
			cout << "\n你喝到了毒药!\n";
			break;
		}
		cout << "\n你喝到了水!\n";
		cnt++;
	}
	cout << "\n存活了" << cnt << "局!";
	return 0;
}
原文