ok I'll try to explain it. If i had a 7-litre(A) and a 5-litre(B ) bowl and access to water. how could I measure exactly 4 litres?
The solution is:1) Fill the A, pour it into the B. At this point "A" bowl has 2 litres in it and "B" is full.
2)I empty "B" and pour with 2litres from A. 3)Fill A with 7 litres and pour 3 litres to B until B is full and A contains 4 litres. This is the solution. The code I have in mind is:
CODE
#include <iostream>
using namespace std;
int massive(int given,int max_bigger_quantity,int max_smaller_quantity){
int smaller_quantity=0,bigger_quantity=0,k=1;
while(smaller_quantity<given){
cout<<"\t~*~*~*~*~*~*~*~*ROUND "<<k<<"~*~*~*~*~*~*~*~*"<<"\n\n\n\n"<<endl;
cout<<"\tFilling bigger glass with "<<max_bigger_quantity<<" ml"<<endl;
bigger_quantity=max_bigger_quantity;
bigger_quantity=bigger_quantity-(max_smaller_quantity-smaller_quantity);
k++;
cout<<"\tMoving "<<max_smaller_quantity-smaller_quantity<<" ml from bigger glass to smaller glass"<<endl;
cout<<"\tMaking smaller glass empty"<<endl;
smaller_quantity=bigger_quantity;
cout<<"\tFilling smaller glass with bigger's quantity: "<<bigger_quantity<<" ml"<<endl;
cout<<"\tMaking bigger glass empty \n\n\n"<<endl;
}
if(given>smaller_quantity)return 0;
else return k;
};
int main(void){
int times=0;
times=massive(40,70,50);
if(times==0)cout<<"Problem cannot be solved"<<endl;
}