# 【程序设计思维与实践 week2 作业题】倒水问题

2020-03-05 21:02:25  阅读：67  来源： 互联网

Sample Input
2 7 5
2 7 4
Sample Output
fill B
pour B A
success
fill A
pour A B
fill A
pour A B
success

## 代码

``````#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<queue>
using namespace std;
int a,b,c;
int x;
void f(){
while (x > a){
x -= a;
cout << "pour B A" <<endl;
cout << "empty A" <<endl;
}
}
void sub(){
while (x != c){
x -= a;
cout << "pour B A" <<endl;
if (x == c){
cout << "success" <<endl;
return;
}
cout << "empty A" <<endl;
}
}
while (x != c){
x += a;
cout << "fill A" <<endl;
cout << "pour A B" <<endl;
if(x == c){
cout << "success" <<endl;
return;
}
}
}
int main(){
//	freopen("1.txt","r",stdin);
while (cin >> a >> b >> c){
x = b;
cout << "fill B" <<endl;
//求正确的模
while (x % a != c % a){
f();
cout << "pour B A" <<endl;
cout << "fill B" <<endl;
cout << "pour B A" <<endl;
cout << "empty A" <<endl;
x = b - a + x;
}
//求解
if (x == c)
cout << "success" <<endl;
if (x > c) sub();
if (x < c) add();
}
return 0;
}
``````