C++ (yuck)
This commit is contained in:
		
							parent
							
								
									1916d57168
								
							
						
					
					
						commit
						82409ba1df
					
				
							
								
								
									
										1
									
								
								cpp/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								cpp/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1 @@
 | 
				
			|||||||
 | 
					problem
 | 
				
			||||||
							
								
								
									
										31
									
								
								cpp/2015/1/problem.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								cpp/2015/1/problem.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,31 @@
 | 
				
			|||||||
 | 
					#include <iostream>
 | 
				
			||||||
 | 
					#include <fstream>
 | 
				
			||||||
 | 
					#include <string>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int main() {
 | 
				
			||||||
 | 
					  std::ifstream input_file ("../data/2015/1/input.txt");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  int floor = 0;
 | 
				
			||||||
 | 
					  while(input_file) {
 | 
				
			||||||
 | 
					    char c = input_file.get(); 
 | 
				
			||||||
 | 
					    if (c == '(') floor++;
 | 
				
			||||||
 | 
					    else if (c == ')') floor--;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  std::cout << "Part 1: " << floor << "\n";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  input_file.clear();
 | 
				
			||||||
 | 
					  input_file.seekg(0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  floor = 0;
 | 
				
			||||||
 | 
					  int steps = 0;
 | 
				
			||||||
 | 
					  while(input_file) {
 | 
				
			||||||
 | 
					    char c = input_file.get(); 
 | 
				
			||||||
 | 
					    if (c == '(') floor++;
 | 
				
			||||||
 | 
					    else if (c == ')') floor--;
 | 
				
			||||||
 | 
					    steps++;
 | 
				
			||||||
 | 
					    if (floor < 0) break;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  std::cout << "Part 2: " << steps << "\n";
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										6
									
								
								cpp/bin/run
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										6
									
								
								cpp/bin/run
									
									
									
									
									
										Executable file
									
								
							@ -0,0 +1,6 @@
 | 
				
			|||||||
 | 
					#!/usr/bin/env bash
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					year=$1
 | 
				
			||||||
 | 
					day=$2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					g++ -o $year/$day/problem $year/$day/problem.cpp && time ./$year/$day/problem
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user