Website Summary Files Commits Branches @commit @diff @stats
path: root / Week13 / Exercise12.cpp
diff options
context:
space:
mode:
1 files changed, 34 insertions, 0 deletions
-rw-r--r--Week13/Exercise12.cpp34
diff --git a/Week13/Exercise12.cpp b/Week13/Exercise12.cpp
new file mode 100644
index 0000000..107281b
--- /dev/null
+++ b/Week13/Exercise12.cpp
@@ -0,0 +1,34 @@
+#include <iostream>
+
+unsigned max(unsigned a, unsigned b) {
+ return a > b ? a : b;
+}
+
+unsigned longestIncreasing(int* nums, unsigned size, unsigned current) {
+ if (size <= 1)
+ return current + size;
+
+ if (nums[0] < nums[1])
+ return longestIncreasing(nums + 1, size - 1, current + 1);
+ else
+ return max(current + 1, longestIncreasing(nums + 1, size - 1, 0));
+}
+
+unsigned longestIncreasing(int* nums, unsigned size) {
+ return longestIncreasing(nums, size, 0);
+}
+
+int main() {
+ unsigned N;
+ std::cin >> N;
+
+ int* nums = new int[N];
+ for (unsigned i = 0; i < N; ++i)
+ std::cin >> nums[i];
+
+ std::cout << longestIncreasing(nums, N) << std::endl;
+
+ delete[] nums;
+
+ return 0;
+}