0916,双色球练习题

 

 while (true)            

{                

int[] shuzu = new int[7];                

Random r = new Random();

               

for (int i = 0; i < 6; i++)                

{                    

shuzu[i] = r.Next(1, 32);

                   

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, 32);

               

Console.Write("请输入红球和篮球,用逗号隔开:");

               

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 == 5 && !islan) || (count == 4 && islan))                

{                    

Console.WriteLine("四等奖");                

}                

else if ((count == 4 && !islan) || (count == 3 && islan))                

{                    

Console.WriteLine("五等奖");                

}                

else if ((count == 2 && islan) || (count == 1 && islan) || (count == 0 && islan))                

{                    

Console.WriteLine("六等奖");                

}                

else                

{                    

Console.WriteLine("未中奖");                

}

 

                Console.ReadLine();

posted @ 2015-09-20 09:00  jlhea  阅读(134)  评论(0编辑  收藏  举报