Dictionary<string, string> dicPZ = new Dictionary<string, string>();
int ZZS = int.Parse(this.txtTotalNum.Text);//总幢数
int ZHS = int.Parse(this.txtHNum.Text);//总户数
if (ZZS==0)
{
XtraMessageBox.Show("总幢数为0");
return;
}
int x = (ZZS) / (checkUsernameList.Count);//商数
int y = (ZZS) % (checkUsernameList.Count);//余数
//整数部分
for (int k = 0; k < checkUsernameList.Count; k++)
{
for (int j = 0; j < x; j = j + x)
{
dicPZ.Add(listZH[k*x+j], checkUsernameList[k]);
}
}
//余数部分
for (int k = 0; k < y; k++)
{
if (x==0)
{
dicPZ.Add(listZH[k], checkUsernameList[k]);
}
else
{
dicPZ.Add(listZH[checkUsernameList.Count * x - 1 + k], checkUsernameList[k]);
}
}
算法:10幢房子分给3个人
最新推荐文章于 2022-05-01 16:25:24 发布