for (Int32 x = 0; x < 20; x++)
{
if(((3*x+300) % 4)!=0)continue;
Int32 z=(3*x+300)/4;
Int32 y = 100 - x-z;
if (x < 0 || y < 0) continue;
Console.WriteLine("5元的"+x+"只,"+"3元的"+(100-x-z)+"只,"+"1元的"+z);
}
Console.Read();
{
if(((3*x+300) % 4)!=0)continue;
Int32 z=(3*x+300)/4;
Int32 y = 100 - x-z;
if (x < 0 || y < 0) continue;
Console.WriteLine("5元的"+x+"只,"+"3元的"+(100-x-z)+"只,"+"1元的"+z);
}
Console.Read();
private static void suanfa()
{
int X = 0;
int Y = 0;
int Z = 0;
for (; X < 20; X++)
{
for (Y = 0; Y < 34; Y++)
{
for (Z = 0; Z < 100; Z++)
{
if (Z % 3 != 0)
continue;
if (5 * X + 3 * Y + Z / 3 != 100)
continue;
if (X + Y + Z != 100)
continue;
// x = X; y = Y; z = Z;
// return;
Console.WriteLine(string.Format("x={0};y={1};z={2}", X, Y, Z));
}
}
}
// x = 0; y = 0; z = 0; }
结果:
x=0;y=25;z=75;
x=4,y=18;z=78;
x=8;y=11;z=81;
x=12,y=4;z=84;