随机购买*问题

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(" 别再买了");
}

原文地址:https://www.cnblogs.com/hz1234/p/4828184.html