收藏 分销(赏)

剪刀石头布作文800字.doc

上传人:xrp****65 文档编号:6862031 上传时间:2024-12-22 格式:DOC 页数:2 大小:16KB 下载积分:10 金币
下载 相关 举报
剪刀石头布作文800字.doc_第1页
第1页 / 共2页
剪刀石头布作文800字.doc_第2页
第2页 / 共2页
本文档共2页,全文阅读请下载到手机保存,查看更方便
资源描述
剪刀石头布作文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; } 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(sf[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(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(你出的是剪刀); } /
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 应用文书 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服