zoukankan      html  css  js  c++  java
  • 例题:石头剪子布。用数组做。比较难理解,主要是逻辑思维

                 Random r = new Random(); //随机定义两个人

                 string[] s1 = new string[] { "剪刀", "石头", "布" };

                string[] s2 = new string[] { "剪刀", "石头", "布" }; //随机定义两个人的数组

                string jg;

                while (true)

                {

                    int sj1 = r.Next(0, 3);  //0代表剪刀,1代表石头,2代表布

                    int sj2 = r.Next(0, 3);

                    if (sj1 == sj2)

                    {

                        jg = "A出的是" + s1[sj1] + ",B出的是" + s2[sj2] + ",结果是平局";

                    }

                    else if (sj1 > sj2)

                    {

                        if (sj1 == 0 && sj2 == 2) //如果随机1出剪刀,随机2出布

                        {

                            jg = "A出的是" + s1[sj1] + ",B出的是" + s2[sj2] + ",结果是B胜利";

                        }

                        else

                        {

                            jg = "A出的是" + s1[sj1] + ",B出的是" + s2[sj2] + "结果是A胜利";

                        }

                    }

                    else

                    {

                        if (sj1 == 2 && sj2 == 0) //如果随机1出布,随机2出剪刀

                        {

                            jg = "A出的是" + s1[sj1] + ",B出的是" + s2[sj2] + ",结果是B胜利";

                        }

                        else

                        {  

                           jg = "A出的是" + s1[sj1] + ",B出的是" + s2[sj2] + ",结果是B胜利";

                        }

                    }

                    Console.WriteLine(jg);

                    Console.ReadLine();

  • 相关阅读:
    python numpy 介绍
    python+图像分割seg
    C++ 添加库
    input标签的disabled和readonly的区别
    linux中mysql忘记密码解决办法
    memcached服务安装与卸载
    app与服务端通信时如何进行消息校验
    缓存同步问题
    数据中添加对字段的说明
    服务器报警
  • 原文地址:https://www.cnblogs.com/275147378abc/p/4428643.html
Copyright © 2011-2022 走看看