From df8bddb55a87f67559a7be7393e16dedc526b188 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20M=C3=A5rdbrink?= Date: Thu, 9 Dec 2021 01:18:52 +0100 Subject: [PATCH] Fixed zero initializers --- solutions/01A.cpp | 2 +- solutions/01B.cpp | 2 +- solutions/02A.cpp | 10 ++++++---- solutions/02B.cpp | 10 ++++++---- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/solutions/01A.cpp b/solutions/01A.cpp index 57d29c5..45b7a5f 100644 --- a/solutions/01A.cpp +++ b/solutions/01A.cpp @@ -9,7 +9,7 @@ int main() { std::vector depths = readToInt("../input/01.txt"); - int increases = 0; + int increases{}; for(auto i = 0; i < depths.size() - 1; i++) increases += 1 * (depths[i] < depths[i+1]); diff --git a/solutions/01B.cpp b/solutions/01B.cpp index 328ee8c..87b2f51 100644 --- a/solutions/01B.cpp +++ b/solutions/01B.cpp @@ -9,7 +9,7 @@ int main() { std::vector depths = readToInt("../input/01.txt"); - int increases = 0; + int increases{}; for(auto i = 0; i < depths.size() - 3; i++) increases += 1 * (depths[i]+depths[i+1]+depths[i+2] < depths[i+1]+depths[i+2]+depths[i+3]); diff --git a/solutions/02A.cpp b/solutions/02A.cpp index 6b459b4..e538d96 100644 --- a/solutions/02A.cpp +++ b/solutions/02A.cpp @@ -8,9 +8,9 @@ const std::vector& readToString(const std::string& path); int main() { std::vector commands = readToString("../input/02.txt"); - long h,d = 0; + long h{},d{}; - for(auto& command : commands) + for(std::string command : commands) { command.pop_back(); int val = command.back() - 48; @@ -23,7 +23,7 @@ int main() } } - std::cout << d*h << std::endl; + std::cout << h*d << std::endl; return 0; } @@ -33,9 +33,11 @@ const std::vector& readToString(const std::string& path) std::ifstream inputFile(path); std::string input; static std::vector inputs; - + while(std::getline(inputFile, input)) inputs.push_back(input); + inputFile.close(); + return inputs; } \ No newline at end of file diff --git a/solutions/02B.cpp b/solutions/02B.cpp index 7e1d53f..0ab2d74 100644 --- a/solutions/02B.cpp +++ b/solutions/02B.cpp @@ -3,12 +3,12 @@ #include #include -const std::vector& readToString(const std::string& path); +std::vector readToString(const std::string& path); int main() { std::vector commands = readToString("../input/02.txt"); - long h,d,a = 0; + long h{},d{},a{}; for(auto& command : commands) { @@ -29,14 +29,16 @@ int main() return 0; } -const std::vector& readToString(const std::string& path) +std::vector readToString(const std::string& path) { std::ifstream inputFile(path); std::string input; - static std::vector inputs; + std::vector inputs; while(std::getline(inputFile, input)) inputs.push_back(input); + inputFile.close(); + return inputs; } \ No newline at end of file