69,374
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
typedef struct _Money
{
float fMon;
int count;
}Money, *PMoney;
Money MonData[4]={{5.0, 7}, {2.0, 3}, {1.0, 0}, {0.5, 0}};
Money temp[4] = {{5.0, 0}, {2.0, 0}, {1.0, 0}, {0.5, 0}};
int find(float fr, int ind)
{
int i = 0, j = 0;
float fsum = 0;
for(i = 0; i <= ind; i++)
{
fsum += temp[i].fMon * temp[i].count;
}
if (fsum == fr)
{
for (j=0; j<ind+1; j++)
{
if(temp[j].count)
printf("(%f * %d) ",temp[j].fMon, temp[j].count);
}
printf("\n");
return 1;
}
else if (fsum > fr) return 0;
else for (i=ind; i<4; i++)
{
if(temp[i].count >= MonData[i].count) continue;
temp[i].count++;
if(find(fr, i))
return 1;
temp[i].count--;
}
}
int main()
{
printf("begin:\n");
if(!find(21.0, 0))
printf("Can not fine result!\n");
getch();
return 0;
}