for练习--凑法

时间:2023-03-09 03:28:28
for练习--凑法
static void Main14购物卡(string[] args)
{
//小明单位发了50元的购物卡,他到超市买洗化用品,一是牙刷(5元),二是香皂(2元),三是牙膏(10元)怎么可以正好把五十元花完。 for (int i = ; i <= ; i++)
{ for (int x = ; x <= ; x++)
{
for (int g = ; g <= ; g++)
{
if (i * + x * + g * == )
{
Console.WriteLine("牙刷\t" + i + "个,香皂\t" + x + "个,牙膏\t" + g + "个");
}
}
}
}
}
 static void Main15白文白鸡(string[] args)
{
//公鸡两文/只,母鸡一文/只,小鸡半文/只,花100文钱,买100只鸡,该如何购买?
Console.WriteLine("买法有:");
int n = ;
for (int a = ; a <= ; a++)
{
for (int b = ; b <= ; b++)
{
for (int c = ; c <= ; c++)
{
if (a + b + c == && a * + b * + c * 0.5 == )
{
n++;
Console.WriteLine("公鸡" + a + "母鸡" + b + "小鸡" + c);
}
}
}
}
Console.WriteLine("共有{0}种买法", n);
}
 static void Main16白马百担(string[] args)
{
//白马百担:大马驮2担粮食,中马驮1担粮食,两头小马驮1担粮食,要用100匹马,驮100担粮食,该如何调配?
int n = ;
for (int a = ; a <= ; a++)
{
for (int b = ; b <= ; b++)
{
for (int c = ; c <= ; c++)
{
if (a + b + c == && a * + b * + c * 0.5 == )
{
n++;
Console.WriteLine("大马{0}\t中马{1}\t小马{2}", a, b, c);
}
}
}
}
Console.WriteLine("共有{0}种驮法", n); }
static void Main17凑钱(string[] args)
{
//有1块、2块、5块的钱若干,凑出20块,有几种凑法? int n = ;
for (int a = ; a <= ; a++)
{
for (int b = ; b <= ; b++)
{
for (int c = ; c <= ; c++)
{
if (a * + b * + c * == )
{
n++;
Console.WriteLine("一块的{0},2块的{1},五块的{2}", a, b, c);
}
}
}
}
Console.WriteLine("共有{0}种凑法", n);
}