随机购买彩票问题
2015-09-22 10:23
260 查看
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别再买了");
}
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别再买了");
}
相关文章推荐
- Oracle SQL优化 总结(学习)
- MyEclipse开发习惯
- VC_16位色和24位色转换宏
- 技术杂谈(1)——Vmware网络连接模式简介
- 有三个线程T1 T2 T3,如何保证他们按顺序执行
- 常用linux命令备忘
- keyChain保存uuid实现唯一标识
- eclipse and systemtap
- for循环小题
- 程序员的激情其实是一种痛苦
- 8月流量入口占比动态:直接访问居首 占比不变
- The processing instruction target matching "[xX][mM][lL]" is not allowed.
- The processing instruction target matching "[xX][mM][lL]" is not allowed.
- The processing instruction target matching "[xX][mM][lL]" is not allowed.
- The processing instruction target matching "[xX][mM][lL]" is not allowed.
- The processing instruction target matching "[xX][mM][lL]" is not allowed.
- The processing instruction target matching "[xX][mM][lL]" is not allowed.
- linux 0号进程 1号进程 区别(转) http://blog.csdn.net/yjzl1911/article/details/5613569
- 通过标签推荐来吸引潜在的用户去对网上的产品做出评论
- socket通讯原理以及tcp、ip三次握手机制分析