注意,条件:B>=C 。应考虑B=C的情况。

#include<iostream>
using namespace std; int A,B,C; void jugs(int a,int b,int C)
{
if(b==C)
{
cout<<"success"<<endl; }
else if(b==B)
{
cout<<"empty B"<<endl;
jugs(a,,C);
}
else if(a==)
{
cout<<"fill A"<<endl;
cout<<"pour A B"<<endl;
if(A+b>=B)
{
a=A-(B-b);
cout<<"empty B"<<endl;
jugs(a,,C);
}
else
{
jugs(,b+A,C);
}
}
else
{
cout<<"pour A B"<<endl;
if(a+b>=B)
{
a=A-(B-b);
cout<<"empty B"<<endl;
jugs(a,,C);
}
else
{
jugs(,a+b,C);
}
}
return; } int main()
{
while(cin>>A>>B>>C)
{ if (A==C)
{
cout<<"fill A"<<endl;
cout<<"success"<<endl;
continue;
}
if (B==C)
{
cout<<"fill B"<<endl;
cout<<"success"<<endl;
continue;
}
jugs(,,C);
}
return ;
}

1.需找bug,参考:

http://www.cnblogs.com/phinecos/archive/2008/09/21/1295472.html

05-26 21:08