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

  • 相关阅读:
    js 获得多个同name 的input输入框的值
    推荐系统
    异常检测
    降维——PCA主成分分析
    无监督学习——降维
    无监督学习——K-means聚类
    支持向量机——内核
    支持向量机背后的数学
    支持向量机——Large Margin Classifier
    支持向量机
  • 原文地址:https://www.cnblogs.com/275147378abc/p/4428643.html
Copyright © 2011-2022 走看看