韩信将兵(普通算法)

private void button1_Click(object sender, EventArgs e)
        {
            int x = 0;
            int y = 0;
            int z = 0;

            for (int i = 1; i <= 33; i++)
            {
                for (int j = 1; j <= 14; j++)
                {
                    for (int k = 1; k <= 20; k++)
                    {
                        if (3 * i +1 == 7 * j  -2&& 7 * j -2 == 5 * k)
                        {
                            x = i;
                            y = j;
                            z = k;
                        }
                    }
                }
            }
            MessageBox.Show("算出来了" +(3*x +1) + "人,3人一行排列" + x + "行,7人一行排列" + y +"行,5人一行排列" +z+"行","韩信将兵人数");
        }

posted @ 2012-07-14 15:04  美丽的矩阵  阅读(202)  评论(0编辑  收藏  举报