//我写了一个,只考虑一种组合,也就是只要称出来重量就行了
#include"iostream.h"
void main()
{
//1,2,5,10,20,50
const N=6;
int i;
int WeightArray[N]={1,2,5,10,20,50};
int Weight;//要称的物体的重量
//从1--88克都计算出来
//都是左盘放物体,右盘放砝码
//如果1,2,5,10,20,50组合不出,则左盘要放砝码
for (int Wt=1;Wt<=88;Wt++)
{
Weight=Wt;
cout<<"称重为"<<Weight<<"g的物体:"<<endl;
////////////////////////////////////////////
//左盘要放砝码的情况
if(Weight%10==4)
{
Weight+=1;
cout<<"左盘放置:"<<endl;
cout<<"1g的砝码"<<endl;
}
if(Weight%10==9)
{
Weight+=1;
cout<<"左盘放置:"<<endl;
cout<<"1g的砝码"<<endl;
}
if(Weight>=40&&Weight<50)
{
Weight+=10;
cout<<"左盘放置:"<<endl;
cout<<"10g的砝码"<<endl;
}
////////////////////////////////////////////////
cout<<"右盘放置:"<<endl;
for(i=N-1;i>=0;i--)
{
if((Weight-WeightArray[i])<0)
{
continue;
}
else
{
Weight-=WeightArray[i];
int temp;
temp=WeightArray[i];
cout<<temp<<"g砝码,";
if(Weight==0)
break;
}
}
cout<<endl;
}
cin>>i;
}