1、剪刀石头布作文800字
篇一:剪刀石头布编程
C++编程剪刀石头布
#includeiostream
#includecstdlib
#includectime
using namespace std;
class Player{ //定义表示玩家的类
private:
int game; //使用game保存出拳的值
public:
Player(int g=0):game(g){};//构造函数
void getGame(){
coutlt;lt;请选择:0—石头 1-剪刀 2-布;
cingame;
2、 }
void autoGame(){
game=rand()%3;//自动出拳
}
void judge(Player c){ // 裁决胜负
const int sf[3][3]={{0,1,-1},{-1,0,1},{1,-1,0}};
coutlt;lt;玩家:lt;lt;(game==0?石头:c.game==1?剪子:布);
coutlt;lt;lt;-电脑:lt;lt;(c.game==0?石头:c.game==1?剪子:布)lt;lt;endl;if(sf[game][c.game]==0) coutlt;lt;平局;
if(s
3、f[game][c.game]==1) coutlt;lt;恭喜!你赢了;
if(sf[game][c.game]==-1) coutlt;lt;哈哈,你输了;
}
};
int main()
{ Player person, computer;//创立两个玩家:person和computer
srand(time(0));//;利用当前时间,初始化随机数序列
person.getGame();//玩家person使用键盘出拳
computer.autoGame();//玩家computer自动出拳
person.judge(compute
4、r);//评判玩家person和computer的胜负
return 0;
}
篇二:剪刀石头布与概率
“剪刀、石头、布” 与概率
文/阳光心语
同学们一定玩过“剪刀、石头、布”的游戏吧,明白吗?在这个游戏中还藏着数学征询题呢。我们一起来看下面这个征询题:A、B两人用石头、剪子、布来做某种决定,求一共有多少种可能的结果?A获胜的可能性是多少?
分析与解:要求一共有多少种结果,我们能够用列举法把A和B猜拳的组合一一列举出来: (剪刀,剪刀)、(剪刀,石头)、(剪刀,布);(石头,剪刀)、(石头,石头)、(石头,布);(布,剪刀)、(布,石头)、(布,布)共9
5、种,因此一共有九种可能的结果。 在这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.ga
6、mes(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(你出的是剪刀);
} /