Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.50 KB | None | 0 0
  1. vector<State> possiblepours(State s, int capA, int capB, int capC) {
  2.     vector<State> possible;
  3.     //C to A
  4.     if (s.a != capA && s.c != 0)
  5.     {
  6.         State temp(s.a,s.b,s.c);
  7.         int pamount;
  8.         temp.directions = s.directions;
  9.         if (temp.c + temp.a <= capA)
  10.         {
  11.             pamount = temp.c;
  12.             temp.a += pamount;
  13.             temp.c = 0;
  14.         }
  15.         else
  16.         {
  17.             pamount = capA - temp.a;
  18.             temp.a += pamount;
  19.             temp.c -= pamount;
  20.         }
  21.         temp.directions.push_back("Pour " + std::to_string(pamount) + " gallons from C to A.");
  22.         possible.push_back(temp);
  23.     }
  24.     //B to A
  25.     if (s.a != capA && s.b != 0)
  26.     {
  27.         State temp(s.a,s.b,s.c);
  28.         temp.directions = s.directions;
  29.         int pamount;
  30.         if (temp.b + temp.a <= capA)
  31.         {
  32.             pamount = temp.b;
  33.             temp.a += pamount;
  34.             temp.b = 0;
  35.         }
  36.         else
  37.         {
  38.             pamount = capA - temp.a;
  39.             temp.a += pamount;
  40.             temp.b -= pamount;
  41.         }
  42.         temp.directions.push_back("Pour " + std::to_string(pamount) + " gallons from B to A.");
  43.         possible.push_back(temp);
  44.     }
  45.     //C to B
  46.     if (s.b != capB && s.c != 0)
  47.     {
  48.         State temp(s.a,s.b,s.c);
  49.         temp.directions = s.directions;
  50.         int pamount;
  51.         if (temp.c + temp.b <= capB)
  52.         {
  53.             pamount = temp.c;
  54.             temp.b += pamount;
  55.             temp.c = 0;
  56.         }
  57.         else
  58.         {
  59.             pamount = capB - temp.b;
  60.             temp.b += pamount;
  61.             temp.c -= pamount;
  62.         }
  63.         temp.directions.push_back("Pour " + std::to_string(pamount) + " gallons from C to B.");
  64.         possible.push_back(temp);
  65.     }
  66.     //A to B
  67.     if (s.b != capB && s.a != 0)
  68.     {
  69.         State temp(s.a,s.b,s.c);
  70.         temp.directions = s.directions;
  71.         int pamount;
  72.         if (temp.a + temp.b <= capB)
  73.         {
  74.             pamount = temp.a;
  75.             temp.b += pamount;
  76.             temp.a = 0;
  77.         }
  78.         else
  79.         {
  80.             pamount = capB - temp.b;
  81.             temp.b += pamount;
  82.             temp.a -= pamount;
  83.         }
  84.         temp.directions.push_back("Pour " + std::to_string(pamount) + " gallons from A to B.");
  85.         possible.push_back(temp);
  86.     }
  87.     //B to C
  88.     if (s.c != capC && s.b != 0)
  89.     {
  90.         State temp(s.a,s.b,s.c);
  91.         temp.directions = s.directions;
  92.         int pamount;
  93.         if (temp.b + temp.c <= capC)
  94.         {
  95.             pamount = temp.b;
  96.             temp.c += pamount;
  97.             temp.b = 0;
  98.         }
  99.         else
  100.         {
  101.             pamount = capC - temp.c;
  102.             temp.c += pamount;
  103.             temp.b -= pamount;
  104.         }
  105.         temp.directions.push_back("Pour " + std::to_string(pamount) + " gallons from B to C.");
  106.         possible.push_back(temp);
  107.     }
  108.     //A to C
  109.     if (s.c != capC && s.a != 0)
  110.     {
  111.         State temp(s.a,s.b,s.c);
  112.         int pamount;
  113.         temp.directions = s.directions;
  114.         if (temp.a + temp.c <= capC)
  115.         {
  116.             pamount = temp.a;
  117.             temp.c += pamount;
  118.             temp.a = 0;
  119.         }
  120.         else
  121.         {
  122.             pamount = capC - temp.c;
  123.             temp.c += pamount;
  124.             temp.a -= pamount;
  125.         }
  126.         temp.directions.push_back("Pour " + std::to_string(pamount) + " gallons from C to A.");
  127.         possible.push_back(temp);
  128.     }
  129.     return possible;
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement