Pujan Day 2 Part 1
This commit is contained in:
		
							parent
							
								
									f66a56294b
								
							
						
					
					
						commit
						8d20a261a9
					
				
							
								
								
									
										1000
									
								
								Day 2/Pujan/data.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1000
									
								
								Day 2/Pujan/data.txt
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								Day 2/Pujan/main
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Day 2/Pujan/main
									
									
									
									
									
										Executable file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										39
									
								
								Day 2/Pujan/main.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								Day 2/Pujan/main.cpp
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,39 @@ | |||||||
|  | #include<iostream> | ||||||
|  | #include <stdlib.h> | ||||||
|  | #include <fstream> | ||||||
|  | 
 | ||||||
|  | int main() | ||||||
|  | { | ||||||
|  |     std::string filename("data.txt"); | ||||||
|  |     std::ifstream input{filename}; | ||||||
|  |     std::string line; | ||||||
|  |      | ||||||
|  |     int horizontal = 0; | ||||||
|  |     int vertical  = 0; | ||||||
|  | 
 | ||||||
|  |     if(!input.is_open()) | ||||||
|  |     { | ||||||
|  |         std::cerr << "Couldn't read file: " << filename << "\n"; | ||||||
|  |         return 1; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     while(std::getline(input,line)) | ||||||
|  |     { | ||||||
|  |         std::string movement = line.substr(0, line.find(" ")); | ||||||
|  |         if (movement == "forward") | ||||||
|  |         { | ||||||
|  |             horizontal += stoi(line.substr(line.find(" "))); | ||||||
|  |         } | ||||||
|  |         else if (movement == "up") | ||||||
|  |         { | ||||||
|  |             vertical -= stoi(line.substr(line.find(" "))); | ||||||
|  |         } | ||||||
|  |         else | ||||||
|  |         { | ||||||
|  |             vertical += stoi(line.substr(line.find(" "))); | ||||||
|  |         } | ||||||
|  |     }  | ||||||
|  | 
 | ||||||
|  |     std::cout << horizontal * vertical << std::endl; | ||||||
|  | 
 | ||||||
|  | } | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user