小明送外卖 C语言
发布网友
发布时间:2022-11-11 03:57
我来回答
共2个回答
热心网友
时间:2024-12-03 04:30
当外卖赚钱那么好赚的啊!!!!!
思路:
各自份数:k(开封菜)c(麦当劳)p(必胜客)
收入: money 总份数:total
k * 20 + c * 12 + p * 8 = money
k + c + p = total -> p = total - c - k
->k*20 + c * 12 + p * 8 = money & p 不能小于0
开始编程:
int main()
{
int k,c,p;
int total,money;
printf("外卖人数:");
scanf("%d", &total);
printf("总收入:");
scanf("%d", &money);
bool found = false;
for (k = 0; k <= total; k ++)
{
for (c = 0; c <= total; c ++)
{
p = total - k - c;
if (p < 0)
{
continue;
}
else
{
int tmp = k * 20 + c * 12 + p * 8;
if (tmp == money)
{
found = true;
printf("KFC = %d MC = %d PIZZ = %d \n", k, c, p);
}
}
}
}
if (!found)
{
printf("No Solution \n");
}
return 0;
}
热心网友
时间:2024-12-03 04:31
#include<stdio.h>
int main()
{
int n,m,i,j,k,flag=1;
scanf("%d%d",&n,&m);
for(i=0;i<=n;i++)
for(j=0;j<=n-i;j++)
for(k=0;k<=n-i-j;k++)
{
if(i*20+j*12+k*8==m)
{
printf("%d %d %d\n",i,j,k);//输出多组,没有排序
flag=0;
}
}
if(flag)printf("No Solution!\n");
return 0;
}