用1,2,3...9组成3个三位数abc,def和ghi,每个数字恰好使用一次,要求abc:def:ghi=1:2:3。输出所以解,希望吓哥们能尽快给出解答效率可能差了点,不过能算出来
int n1;
int n2;
int n3;
for (int i = 123456789; i <= 333333333; i = i + 3)
{
char[] num = i.ToString().ToCharArray();
Array.Sort(num);
if (new string(num) == "123456789")
{
n1 = i / 1000000;
n2 = (i - n1 * 1000000)/1000;
n3 = i % 1000;
if (n2 / (double)n1 == 2 && n3 / (double)n1 == 3)
Console.WriteLine(n1 + " " + n2 + " " + n3);
}
}
结果
192 384 576
219 438 657
273 546 819
327 654 981