while (true) { //数组:一组同类型的数据,数组是有长度的,数组是有索引的,索引从0开始 int[] shuzu = new int[7];//定义了一个长度为6的int类型的数组 Random r = new Random(); for (int i = 0; i < 6; i++)//循环生成六个数 { shuzu[i] = r.Next(1, 34);//生成一个数 bool isok = false; for (int j = 0; j < i; j++)//比较是否跟之前的书相等 { if (shuzu[j] == shuzu[i]) { isok = true; } } if (isok) { i--;//后退一步 continue; } } shuzu[6] = r.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.Write("一等奖"); } else if (count == 6 && !islan) { Console.Write("二等奖"); } else if (count == 5 && islan) { Console.Write("三等奖"); } else if ((count == 4 && islan) || (count == 5 && !islan)) { Console.Write("四等奖"); } else if ((count == 3 && islan) || (count == 4 && !islan)) { Console.Write("五等奖"); } else if ((count == 2 && islan) || (count == 1 && islan) || (count == 0 && islan)) { Console.Write("五块钱"); } else { Console.Write("别再买了"); } Console.ReadLine(); }
时间: 2024-11-08 19:58:10