Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void solve(int cup1, int cup2, int cup3, int target) {
- if (cup1 == target || cup2 == target || cup3 == target) {
- cout << endl << "Done!";
- return;
- }
- if (cup1 == 8) {
- cup1 -= 3;
- cup2 = 3;
- cout << endl << "A -> B";
- solve(cup1, cup2, cup3, target);
- } else if (cup2 == 3) {
- int remain3 = 5 - cup3;
- if (remain3 < cup2) {
- cup2 -= remain3;
- cup3 = 5;
- cout << endl << "B -> C";
- solve(cup1, cup2, cup3, target);
- } else {
- cup3 += cup2;
- cup2 = 0;
- cout << endl << "B -> C";
- solve(cup1, cup2, cup3, target);
- }
- } else if (cup3 == 5) {
- cup1 += cup3;
- cup3 = 0;
- cout << endl << "C -> A";
- solve(cup1, cup2, cup3, target);
- } else {
- if (cup2 == 0) {
- cup1 -= 3;
- cup2 = 3;
- cout << endl << "A -> B";
- solve(cup1, cup2, cup3, target);
- } else if (cup3 == 0) {
- cup3 += cup2;
- cup2 = 0;
- cout << endl << "B -> C";
- solve(cup1, cup2, cup3, target);
- } else {
- int remain3 = 5 - cup3;
- if (remain3 < cup2) {
- cup2 -= remain3;
- cup3 = 5;
- cout << endl << "B -> C";
- solve(cup1, cup2, cup3, target);
- } else {
- cup2 = 0;
- cup3 += cup2;
- cout << endl << "B -> C";
- solve(cup1, cup2, cup3, target);
- }
- }
- }
- }
- int main()
- {
- int n;
- cout << "n = "; cin >> n;
- solve(8, 0, 0, n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement