数据比对求算法
A 数组: B数组:100 10
90 67
70 23
80 75
40 55
30 45
99 10
88 10
... ...
A数据等于B数据相加之和或者几个A数据相加等于B数据相加
A:100 匹配 B:55+45
A:90 匹配 B:67+23
A:30 匹配 B:10+10+10
我的思路:先循环A数据列:100 先和 B的两个数相加比对
100 10+67 10+23 10+75 10+55 10+45 10+10 10+10
67+23 67+75 67+55 67+45 67+10 67+10
判断23、75
55+45=100 匹配!
再判断90 .....
private double[,] CheckArry(double [,] bank,double [,] qy)
{
double bankv = 0, qyv=0,tmp = 0;
bool find = false;
for (int i = 0; i < bank.GetLength(0); i++)
{
bankv = bank[i,0]; if (bankv == 9)
break;
find = false;
qyv = 0;
tmp = 0;
for (int j = 0; j < qy.GetLength(0); j++)
{
qyv = qy[j,0];
if (qy[j,1] == 9)
break;
richTextBox1.AppendText("\n");
for (int jj = j+1; jj < qy.GetLength(0); jj++)//下一条记录
{
if (qy[jj, 1] == 9)
continue;
tmp = qyv + qy[jj,0];
if (qy[jj,1]!=9)
{
if (tmp == bankv)
{
setcolor(bankv.ToString() + "?" + qyv.ToString() + "+" + qy[jj, 0].ToString() + "=" + tmp.ToString() + "相等\n");
//richTextBox1.AppendText(bankv.ToString()+"?"+qyv.ToString() + "+" + qy[jj, 0].ToString() + "=" + tmp.ToString() + "相等\n");
bank[i, 1] = 9;//999找到了
qy[j, 1] = 9;
qy[jj, 1] = 9;
find = true;
break;
}
else
richTextBox1.AppendText(bankv.ToString()+"?"+qyv.ToString() + "+" + qy[jj, 0].ToString() + "=" + tmp.ToString() + "\n");
}
} }
if (find)
break;
}
}
return bank;
}