随机购买彩票问题

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("\n一等奖");
}
else if (count == 6 && !islan)
{
Console.WriteLine("\n二等奖");
}
else if (count == 5 && islan)
{
Console.WriteLine("\n三等奖");
}
else if ((count == 4 && islan) || (count == 5 && !islan))
{
Console.WriteLine("\n四等奖");
}
else if ((count == 3 && islan) || (count == 4 && !islan))
{
Console.WriteLine("\n五等奖");
}
else if ((count == 2 && islan) || (count == 1 && islan) || (count == 0 && islan))
{
Console.WriteLine("\n五块钱");
}
else
{
Console.WriteLine("\n别再买了");
}

posted on 2015-09-22 10:23  路人甲zzz  阅读(121)  评论(0编辑  收藏  举报

导航