剪刀石头布作文800字

2020-05-06 │ 节目游戏

篇一:剪刀石头布编程

C++编程剪刀石头布

#include"iostream"

#include"cstdlib"

#include"ctime"

using namespace std;

class Player{ //定义表示玩家的类

private:

int game; //使用game保存出拳的值

public:

Player(int g=0):game(g){};//构造函数

void getGame(){

cout<<"请选择:0—石头 1-剪刀 2-布";

cin>>game;

}

void autoGame(){

game=rand()%3;//自动出拳

}

void judge(Player c){ // 裁决胜负

const int sf[3][3]={{0,1,-1},{-1,0,1},{1,-1,0}};

cout<<"玩家:"<<(game==0?"石头":c.game==1?"剪子":"布");

cout<<"<->电脑:"<<(c.game==0?"石头":c.game==1?"剪子":"布")<<endl;if(sf[game][c.game]==0) cout<<"平局";

if(sf[game][c.game]==1) cout<<"恭喜!你赢了";

if(sf[game][c.game]==-1) cout<<"哈哈,你输了";

}

};

int main()

{ Player person, computer;//创建两个玩家:person和computer

srand(time(0));//;利用当前时间,初始化随机数序列

person.getGame();//玩家person使用键盘出拳

computer.autoGame();//玩家computer自动出拳

person.judge(computer);//评判玩家person和computer的胜负

return 0;

}

篇二:剪刀石头布与概率

“剪刀、石头、布” 与概率

文/阳光心语

同学们一定玩过“剪刀、石头、布”的游戏吧,知道吗?在这个游戏中还藏着数学问题呢。我们一起来看下面这个问题:A、B两人用石头、剪子、布来做某种决定,求一共有多少种可能的结果?A获胜的可能性是多少?

分析与解:要求一共有多少种结果,我们可以用列举法把A和B猜拳的组合一一列举出来: (剪刀,剪刀)、(剪刀,石头)、(剪刀,布);(石头,剪刀)、(石头,石头)、(石头,布);(布,剪刀)、(布,石头)、(布,布)共9种,所以一共有九种可能的结果。 在这9种组合中,A获胜的组合一共有(剪刀,布)、(石头,剪刀)、(布,石头)3种,那么A获胜的概率就是3/9=1/3。

篇三:JAVA 编程剪刀石头布

import java.util.*;

class Game1{

public static void main(String[] args){

System.out.println("欢迎来到剪刀石头布游戏");People p=new People();

Computer c=new Computer();

Referee r=new Referee();

r.games(p,c);

}

}

class People{

public int chuQuan(){

Scanner sc=new Scanner(System.in);

System.out.println("请出拳");

int a=sc.nextInt();

return a;

}

}

class Computer{

public int chuQuan(){

int a=new Random().nextInt(3);

return a;

}

}

class Referee{

public void games(People p1,Computer c1){int a=p1.chuQuan();

int b=c1.chuQuan();

switch(a){

case 0:

System.out.println("你出的是石头"); break;

case 1:

System.out.println("你出的是布"); break;

default:

System.out.println("你出的是剪刀");

} //} } switch(b){ case 0:System.out.println("电脑出的是石头");break; case 1:System.out.println("电脑出的是布");break; default:System.out.println("电脑出的是剪刀"); } //a//0 石头,1 布,2 剪刀 b//0 石头,1 布,2 剪刀 int c=a-b; if(c==0){ System.out.println("打平了"); }else if(c==-2||c==1){System.out.println("恭喜你,你赢了"); }else{System.out.println("再接再厉"); } Scanner sc=new Scanner(System.in); System.out.println("是否继续Y是,N否"); String str=sc.nextLine(); if(str.equals("Y")){ Referee r=new Referee(); r.games(p1,c1); }else return;

剪刀石头布作文800字

查看更多节目游戏相关内容,请点击节目游戏
推荐访问:玩石头剪刀布作文 怎么写石头剪刀布游戏
作文 论文 简历 文秘 合同 文库 计划 总结 体会 报告 策划 材料 公文 礼仪 思想 党团 演讲稿 企事业 发言致辞 资讯