From 9242ebc4c69f2c1f550ddcc0e9235f3f409554c7 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 1 Nov 2025 20:27:21 +0200 Subject: feat(Week05): Add exercises and solutions --- Week05/Exercise12.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Week05/Exercise12.cpp (limited to 'Week05/Exercise12.cpp') diff --git a/Week05/Exercise12.cpp b/Week05/Exercise12.cpp new file mode 100644 index 0000000..eac5f08 --- /dev/null +++ b/Week05/Exercise12.cpp @@ -0,0 +1,26 @@ +#include + +int main() { + const unsigned int SIZE = 20; + + unsigned short indecies[SIZE]; + bool visited[SIZE]; + for (unsigned int i = 0; i < SIZE; i++) { + std::cin >> indecies[i]; + visited[i] = false; + } + + unsigned int current_index = 0, jumps = 0; + while (current_index != SIZE - 1 && !visited[current_index]) { + visited[current_index] = true; + current_index = indecies[current_index]; + jumps++; + } + + if (current_index != SIZE - 1) + std::cout << "Infinity" << std::endl; + else + std::cout << jumps << std::endl; + + return 0; +} -- cgit v1.3.1-23-gd82d