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();

  • 相关阅读:
    理解OpenShift(5):从 Docker Volume 到 OpenShift Persistent Volume
    理解OpenShift(4):用户及权限管理
    理解OpenShift(3):网络之 SDN
    理解OpenShift(2):网络之 DNS(域名服务)
    理解OpenShift(1):网络之 Router 和 Route
    HTML盒子模型
    架构系统的雪崩理解
    C++11 lambda表达式学习
    C++11 std::shared_ptr总结与使用
    Kafka学习笔记
  • 原文地址:https://www.cnblogs.com/275147378abc/p/4428643.html
Copyright © 2011-2022 走看看