Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- vector<State> possiblepours(State s, int capA, int capB, int capC) {
- vector<State> possible;
- //C to A
- if (s.a != capA && s.c != 0)
- {
- State temp(s.a,s.b,s.c);
- int pamount;
- temp.directions = s.directions;
- if (temp.c + temp.a <= capA)
- {
- pamount = temp.c;
- temp.a += pamount;
- temp.c = 0;
- }
- else
- {
- pamount = capA - temp.a;
- temp.a += pamount;
- temp.c -= pamount;
- }
- temp.directions.push_back("Pour " + std::to_string(pamount) + " gallons from C to A.");
- possible.push_back(temp);
- }
- //B to A
- if (s.a != capA && s.b != 0)
- {
- State temp(s.a,s.b,s.c);
- temp.directions = s.directions;
- int pamount;
- if (temp.b + temp.a <= capA)
- {
- pamount = temp.b;
- temp.a += pamount;
- temp.b = 0;
- }
- else
- {
- pamount = capA - temp.a;
- temp.a += pamount;
- temp.b -= pamount;
- }
- temp.directions.push_back("Pour " + std::to_string(pamount) + " gallons from B to A.");
- possible.push_back(temp);
- }
- //C to B
- if (s.b != capB && s.c != 0)
- {
- State temp(s.a,s.b,s.c);
- temp.directions = s.directions;
- int pamount;
- if (temp.c + temp.b <= capB)
- {
- pamount = temp.c;
- temp.b += pamount;
- temp.c = 0;
- }
- else
- {
- pamount = capB - temp.b;
- temp.b += pamount;
- temp.c -= pamount;
- }
- temp.directions.push_back("Pour " + std::to_string(pamount) + " gallons from C to B.");
- possible.push_back(temp);
- }
- //A to B
- if (s.b != capB && s.a != 0)
- {
- State temp(s.a,s.b,s.c);
- temp.directions = s.directions;
- int pamount;
- if (temp.a + temp.b <= capB)
- {
- pamount = temp.a;
- temp.b += pamount;
- temp.a = 0;
- }
- else
- {
- pamount = capB - temp.b;
- temp.b += pamount;
- temp.a -= pamount;
- }
- temp.directions.push_back("Pour " + std::to_string(pamount) + " gallons from A to B.");
- possible.push_back(temp);
- }
- //B to C
- if (s.c != capC && s.b != 0)
- {
- State temp(s.a,s.b,s.c);
- temp.directions = s.directions;
- int pamount;
- if (temp.b + temp.c <= capC)
- {
- pamount = temp.b;
- temp.c += pamount;
- temp.b = 0;
- }
- else
- {
- pamount = capC - temp.c;
- temp.c += pamount;
- temp.b -= pamount;
- }
- temp.directions.push_back("Pour " + std::to_string(pamount) + " gallons from B to C.");
- possible.push_back(temp);
- }
- //A to C
- if (s.c != capC && s.a != 0)
- {
- State temp(s.a,s.b,s.c);
- int pamount;
- temp.directions = s.directions;
- if (temp.a + temp.c <= capC)
- {
- pamount = temp.a;
- temp.c += pamount;
- temp.a = 0;
- }
- else
- {
- pamount = capC - temp.c;
- temp.c += pamount;
- temp.a -= pamount;
- }
- temp.directions.push_back("Pour " + std::to_string(pamount) + " gallons from C to A.");
- possible.push_back(temp);
- }
- return possible;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement