zoukankan      html  css  js  c++  java
  • 随机购买*问题

    int[] shuzu = new int[7];
    Random suiji = new Random();

    for (int i = 0; i < 6; i++)
    {
    shuzu[i] = suiji.Next(1, 34);
    bool isok = false;
    for (int j = 0; j < i; j++)
    {
    if (j > 0)
    {
    if (shuzu[i] == shuzu[j])
    {
    isok = true;
    }
    }
    }
    if (isok)
    {
    i--;
    continue;
    }
    }
    shuzu[6] = suiji.Next(1, 17);

    Console.Write("请输入6个红球,1个蓝球,用逗号隔开:");
    string shuru = Console.ReadLine();
    string[] ren = shuru.Split(',');

    int count = 0;

    for (int i = 0; i < 6; i++)
    {
    for (int j = 0; j < 6; j++)
    {
    if (int.Parse(ren[i]) == shuzu[j])
    {
    count++;
    }
    }
    }
    //判断蓝球中没中
    bool islan = false;
    if (int.Parse(ren[6]) == shuzu[6])
    {
    islan = true;
    }

    //输出电脑随机的中奖号码
    foreach (int a in shuzu)
    {
    Console.Write(a + " ");
    }

    //判断中几等奖
    if (count == 6 && islan)
    {
    Console.WriteLine(" 一等奖");
    }
    else if (count == 6 && !islan)
    {
    Console.WriteLine(" 二等奖");
    }
    else if (count == 5 && islan)
    {
    Console.WriteLine(" 三等奖");
    }
    else if ((count == 4 && islan) || (count == 5 && !islan))
    {
    Console.WriteLine(" 四等奖");
    }
    else if ((count == 3 && islan) || (count == 4 && !islan))
    {
    Console.WriteLine(" 五等奖");
    }
    else if ((count == 2 && islan) || (count == 1 && islan) || (count == 0 && islan))
    {
    Console.WriteLine(" 五块钱");
    }
    else
    {
    Console.WriteLine(" 别再买了");
    }

  • 相关阅读:
    PowerShell 学习(一):运算符
    Create word clouds with Wordle
    淘宝惊现“同店购”?
    “二叉查找树”学习
    云计算软件之——OpenNebula
    "栈"应用——求解迷宫
    "队列"学习
    “串”学习——三种表示方法
    尖端技术104之计算机技术的未来
    “二叉树”——链表表示
  • 原文地址:https://www.cnblogs.com/hz1234/p/4828184.html
Copyright © 2011-2022 走看看