From 0996e05988b5d38faba0f616f06e6dcc7466930e Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 3 Dec 2023 13:33:32 +0200 Subject: [w6] Added solutions for ex1 and ex2 with partials for ex3 and 4 --- week06/ex2.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 week06/ex2.cpp (limited to 'week06/ex2.cpp') diff --git a/week06/ex2.cpp b/week06/ex2.cpp new file mode 100644 index 0000000..1c217bf --- /dev/null +++ b/week06/ex2.cpp @@ -0,0 +1,28 @@ +#include + +int main() { + size_t N; + std::cin >> N; + + unsigned nums[30]; + for (size_t i = 0; i < N; i++) { + std::cin >> nums[i]; + } + + bool lastWas = false; + unsigned count = 0; + + bool hasGE = true; + for (unsigned comp = 1; hasGE; comp++) { + hasGE = false; + for (size_t i = 0; i < N; i++) { + if ((nums[i] >= comp) != lastWas) { + if (!lastWas) count++; + lastWas = !lastWas; + hasGE = true; + } + } + } + + std::cout << count << std::endl; +} -- cgit v1.2.3