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-2.cpp | 59 +++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 challenge-196/paulo-custodio/cpp/ch-2.cpp (limited to 'challenge-196/paulo-custodio/cpp/ch-2.cpp') diff --git a/challenge-196/paulo-custodio/cpp/ch-2.cpp b/challenge-196/paulo-custodio/cpp/ch-2.cpp new file mode 100644 index 0000000000..04c5a3f0b1 --- /dev/null +++ b/challenge-196/paulo-custodio/cpp/ch-2.cpp @@ -0,0 +1,59 @@ +/* +Challenge 197 + +Task 2: Range List +Submitted by: Mohammad S Anwar +You are given a sorted unique integer array, @array. + +Write a script to find all possible Number Range i.e [x, y] represent range +all integers from x and y (both inclusive). + + +Each subsequence of two or more contiguous integers + + +Example 1 +Input: @array = (1,3,4,5,7) +Output: [3,5] +Example 2 +Input: @array = (1,2,3,6,7,9) +Output: [1,3], [6,7] +Example 3 +Input: @array = (0,1,2,4,5,6,8,9) +Output: [0,2], [4,6], [8,9] +*/ + +#include +#include +#include + +void print_ranges(const std::vector& nums) { + int nums_size=static_cast(nums.size()); + std::cout<<"("; + std::string sep=""; + for (int i=0; i1) { + std::cout< nums; + for (int i=0; i