回复 楼主 jaksok
这道题应分多种情况,下面是给出个参考 希望对你有帮助void main()
{
int x,y,z;
float i;
const float m_x=0.1,m_y=1.5,m_z=3;
cout<<"只买单种鸡蛋情况明显不成立"<<endl<<endl;
cout<<"买鸡蛋和鸭蛋情况"<<endl;
for(x=0;x<=100;x++)
{
for(y=0;y<=100;y++)
{
i=x*m_x+y*m_y;
if(((x+y)==100)&&(i==100))
cout<<"鸡蛋"<<x<<"鸭蛋"<<y<<endl<<endl;
}
}
if(!(((x+y)==100)&&(i==100)))
cout<<"买鸡蛋和鸭蛋情况不成立"<<endl<<endl;
cout<<"买鸡蛋和鹅蛋情况"<<endl;
for(x=0;x<=100;x++)
{
for(z=0;z<=100;z++)
{
i=x*m_x+z*m_z;
if(((x+z)==100)&&(i==100))
{ cout<<"鸡蛋"<<x<<"鹅蛋"<<z<<endl;}
}
}
if(!(((x+z)==100)&&((x*m_x+z*m_z)==100)))
cout<<"买鸡蛋和鹅蛋不成立"<<endl<<endl;
cout<<"买鸭蛋和鹅蛋情况"<<endl;
for(y=0;y<=100;y++)
{
for(z=0;z<=100;z++)
{
if(((z+y)==100)&&((y*m_y+z*m_z)==100))
{ cout<<"鸭蛋"<<y<<"鹅蛋"<<z<<endl;}
}
}
if(!(((z+y)==100)&&((y*m_y+z*m_z)==100)))
cout<<"买鸭蛋和鹅蛋不成立"<<endl<<endl;
cout<<"三种蛋都买的情况"<<endl;
for(x=0;x<=100;x++)
{
for(y=0;y<=100;y++)
{
for(z=0;z<=100;z++)
{
i=x*m_x+y*m_y+z*m_z;
if((x+y+z)==100&&(i==100))
cout<<"鸡蛋:"<<x<<"鸭蛋:"<<y<<"鹅蛋:"<<z<<endl;
}
}
}
}
如果改变了事情就尝试改变自己。