c# array的问题 怎么找出相同的个数
int[][]lottoNumbers={newint[]{4,7,19,23,28,36},newint[]{14,18,26,34,38,45},newint[]{8...
int[][] lottoNumbers = { new int [] {4, 7, 19, 23, 28, 36}, new int [] {14, 18, 26, 34, 38, 45}, new int [] {8, 10, 11, 19, 28, 30}, new int [] {15, 17, 19, 24, 43, 44}, new int [] {10, 27, 29, 30, 32, 41}, new int [] {9, 13, 26, 32, 37, 43}, new int [] {1, 3, 25, 27, 35, 41}, new int [] {7, 9, 17, 26, 28, 44}, new int [] {17, 18, 20, 28, 33, 38} };int[] drawnNumbers = new int[] { 44, 9, 17, 43, 26, 7, 28, 19 };(这个前6个是winning numbers 后面两个是supplementary numbers)这个就是检测是否中奖没得功能怎么可以做出像图里那样??
展开
2个回答
2016-11-28
展开全部
用循环啊。
for(int k=0; k<lottoNumbers.Length; k++)
{
int[] oneLotto = lottoNumbers[k];
int foundWinning = 0, foundSupple = 0;
for(int i=0; i<6; i++)
{
foreach(int num in oneLotto)
{
if (drawnNumbers[i]==num)
foundWinning++;
}
}
for(int i=6; i<drawnNumbers.Length; i++)
{
foreach(int num in oneLotto)
{
if (drawnNumbers[i]==num)
foundSupple++;
}
}
Console.WriteLine(string.Format("found {0} winning number/s and {1} supplementary numbers/s in Game {2}", foundWinning, foundSupple,k));
}
展开全部
int[] supplementary=new int[]{drawnNumbers[6],drawnNumbers[7]};
for(int i=0;i<lottoNumbers.Length;i++)
{
var distinct=lottoNumbers[i].Distinct();
int total=distinct.Intersect(drawnNumbers).Count();
int supple=distinct.Intersect(supplementary).Count();
Console.WriteLine("found {0} winning number/s and {1} supplementary numbers/s in Game {2}", total - supple, supple, i);
}
Console.ReadKey();
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询