"""#include <iostream>\n#include <cstdlib>\n#include <ctime>\n\nusing namespace std;\n\nint main() {\n srand(time(0)); // 初始化随机种子\n\n int playerChoice;\n int computerChoice;\n\n cout << "石头剪刀布游戏" << endl;\n cout << "------------------" << endl;\n cout << "1. 石头" << endl;\n cout << "2. 剪刀" << endl;\n cout << "3. 布" << endl;\n cout << "请输入您的选择(1-3): " << endl;\n cin >> playerChoice;\n\n computerChoice = rand() % 3 + 1; // 生成计算机的随机选择\n\n cout << "计算机选择了: " << computerChoice << endl;\n\n // 判断胜负\n if (playerChoice == computerChoice) {\n cout << "平局!" << endl;\n } else if ((playerChoice == 1 && computerChoice == 2) ||\n (playerChoice == 2 && computerChoice == 3) ||\n (playerChoice == 3 && computerChoice == 1)) {\n cout << "恭喜,您赢了!" << endl;\n } else {\n cout << "很遗憾,您输了!" << endl;\n }\n\n return 0;\n}"""\n这个代码会首先让玩家输入自己的选择(1代表石头,2代表剪刀,3代表布),然后计算机会随机生成一个选择。接下来,根据玩家和计算机的选择进行判断,输出胜负结果。


原文地址: https://www.cveoy.top/t/topic/pOJ3 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录