From 203478bbfe21091f94c4559377f730f75e688dfd Mon Sep 17 00:00:00 2001 From: Paulo Custodio Date: Sun, 26 Mar 2023 00:28:56 +0000 Subject: Add Perl, C, C++, BASIC and Forth solutions --- challenge-196/paulo-custodio/cpp/ch-1.cpp | 60 +++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 challenge-196/paulo-custodio/cpp/ch-1.cpp (limited to 'challenge-196/paulo-custodio/cpp/ch-1.cpp') diff --git a/challenge-196/paulo-custodio/cpp/ch-1.cpp b/challenge-196/paulo-custodio/cpp/ch-1.cpp new file mode 100644 index 0000000000..8c62d7d84e --- /dev/null +++ b/challenge-196/paulo-custodio/cpp/ch-1.cpp @@ -0,0 +1,60 @@ +/* +Challenge 197 + +Task 1: Pattern 132 +Submitted by: Mohammad S Anwar +You are given a list of integers, @list. + +Write a script to find out subsequence that respect Pattern 132. Return empty array if none found. + + +Pattern 132 in a sequence (a[i], a[j], a[k]) such that i < j < k and a[i] < a[k] < a[j]. + + +Example 1 +Input: @list = (3, 1, 4, 2) +Output: (1, 4, 2) respect the Pattern 132. +Example 2 +Input: @list = (1, 2, 3, 4) +Output: () since no susbsequence can be found. +Example 3 +Input: @list = (1, 3, 2, 4, 6, 5) +Output: (1, 3, 2) if more than one subsequence found then return the first. +Example 4 +Input: @list = (1, 3, 4, 2) +Output: (1, 3, 2) +*/ + +#include +#include + +void print_patter132(const std::vector& nums) { + int nums_size=static_cast(nums.size()); + std::cout<<"("; + for (int i=0; i nums; + for (int i=0; i