7.百钱买百鸡。用100元钱买100只鸡,公鸡每只5元,母鸡每只3元,小鸡没3只1元,要求每种鸡至少买一只,且必须是整数只,问公鸡、母鸡和小鸡各买几只?
#include<iostream.h>
main()
{ int cock,hen,chicken;
for(cock=1;cock<16;cock++)
for(hen=1;hen<29;hen++)
{ chicken=100-cock-hen;
if(5*cock+3*hen+chicken/3==100 && chicken%3==0)
{ cout<<"cock="<<cock<<" ";
cout<<"hen="<<hen<<" ";
cout<<"chicken="<<chicken<<endl;
}}}
不是很懂代码思路····(小白一枚)