本帖最后由 aixuexi 于 2014-1-2 16:35 编辑
[C#] 纯文本查看 复制代码 bool[] states = new bool[100];
private void lamps_Load(object sender, EventArgs e)
{
//给100个灯泡状态初值;
for (int i = 0; i < 100; i++)
{
states[i] = false;
}
}
#region 第j个同学进行拉灯
public void Operate(int j)
{
for (int k = 1; k < 101; k++)
{
if (Math.IEEERemainder(k,j)==0) //获得操作权
{
if (states[k - 1] == true) //改变两种状态
{ states[k - 1] = false; }
else if (states[k - 1] == false)
{ states[k - 1] = true; }
}
}
}
#endregion
private void button1_Click(object sender, EventArgs e)
{
for (int j = 1; j < 101; j++) //遍历100个同学操作
{
Operate(j);
}
for (int m = 0; m < 100; m++)
{
if (states[m] == true)
{
textBox1.Text += m + 1 + " ";
}
}
} |