Finished part 2.
This commit is contained in:
		@@ -1,6 +1,7 @@
 | 
			
		||||
#include <algorithm>
 | 
			
		||||
#include <fstream>
 | 
			
		||||
#include <iostream>
 | 
			
		||||
#include <stack>
 | 
			
		||||
#include <string>
 | 
			
		||||
#include <vector>
 | 
			
		||||
 | 
			
		||||
@@ -41,6 +42,7 @@ int main()
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	std::vector<std::vector<char>> stacks;
 | 
			
		||||
	std::vector<std::vector<char>> stacks2;
 | 
			
		||||
 | 
			
		||||
	// Step 1: Parse Starting Position
 | 
			
		||||
	for(std::string line; std::getline(ifs, line); )
 | 
			
		||||
@@ -64,6 +66,7 @@ int main()
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// DebugOutput(stacks);
 | 
			
		||||
	stacks2 = stacks;
 | 
			
		||||
 | 
			
		||||
	// Step 3: Parse Actions
 | 
			
		||||
	for(std::string line; std::getline(ifs, line); )
 | 
			
		||||
@@ -82,11 +85,25 @@ int main()
 | 
			
		||||
		long from = std::atoi(actions[3].c_str()) - 1;
 | 
			
		||||
		long to = std::atoi(actions[5].c_str()) - 1;
 | 
			
		||||
 | 
			
		||||
		// Part 1:
 | 
			
		||||
		for(auto i = 0; i < amt; ++i)
 | 
			
		||||
		{
 | 
			
		||||
			stacks[to].push_back(stacks[from].back());
 | 
			
		||||
			stacks[from].pop_back();
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// Part 2:
 | 
			
		||||
		std::stack<char> temp;
 | 
			
		||||
		for(auto i = 0; i < amt; ++i)
 | 
			
		||||
		{
 | 
			
		||||
			temp.push(stacks2[from].back());
 | 
			
		||||
			stacks2[from].pop_back();
 | 
			
		||||
		}
 | 
			
		||||
		for(auto i = 0; i < amt; ++i)
 | 
			
		||||
		{
 | 
			
		||||
			stacks2[to].push_back(temp.top());
 | 
			
		||||
			temp.pop();
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// DebugOutput(stacks);
 | 
			
		||||
@@ -94,6 +111,9 @@ int main()
 | 
			
		||||
	for(const auto &st : stacks)
 | 
			
		||||
		std::cout << st.back();
 | 
			
		||||
	std::cout << std::endl;
 | 
			
		||||
	for(const auto &st : stacks2)
 | 
			
		||||
		std::cout << st.back();
 | 
			
		||||
	std::cout << std::endl;
 | 
			
		||||
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user