跳到正文

休闲·娱乐

石头剪刀布(人机版)

CSP400pts约 2 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年7月21日
篇幅
约 2 分钟

版本

  1. v1当前
C++
#include<bits/stdc++.h>
#include<ctime>
#include<queue>
#include<set>
#include<string>
#include<cstring>
#include<stack>
#include<cmath>
#include<vector>
#include<map>
#include<iostream> 
using namespace std;
int t,ans1,ans2; 
int main()
{
	srand(time(NULL));
	cout<<"游戏开始!"<<endl;
	cout<<"请输入你想玩的局数:";
	cin>>t;
	while(t--)
	{
		cout<<"请输入你要出的动作:"<<endl;
		cout<<"1表示石头 2表示剪刀 3表示布"<<endl;
		int op;
		cin>>op;
		while(op<=0||op>=4) {
			cout<<"输入错误,请重新输入"<<endl;
			cin>>op;
		}
		int max=3;
		int min=1;
		int k=min+rand()%(max-min+1);
		if(op==1)
		{
			if(k==1) cout<<"平局"<<endl;
			else if(k==2) cout<<"你赢了"<<endl,ans1++;
			else cout<<"你输了"<<endl,ans2++;
		}
		if(op==2)
		{
			if(k==1) cout<<"你输了"<<endl,ans2++;
			else if(k==2) cout<<"平局"<<endl;
			else cout<<"你赢了"<<endl,ans1++; 
		}
		if(op==3)
		{
			if(k==1) cout<<"你赢了"<<endl,ans1++;
			else if(k==2) cout<<"你输了"<<endl,ans2++;
			else cout<<"平局"<<endl; 
		}
		if(t>1) cout<<"此时的大比分:"<<ans1<<":"<<ans2<<endl;
	}
	cout<<"最终:";
	if(ans1==ans2) cout<<"平局";
	if(ans1>ans2) cout<<"你获胜了!!!";
	if(ans1<ans2) cout<<"你输了,继续加油!";
	return 0;
}
//CSP400pts 写 
原文