From 3c934ca8f0f3d6122863c26dc4d726965a37ed1c Mon Sep 17 00:00:00 2001 From: deadmarshal Date: Sat, 4 Nov 2023 19:38:44 +0330 Subject: TWC127 --- challenge-127/deadmarshal/cpp/ch-2.cpp | 37 ++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 challenge-127/deadmarshal/cpp/ch-2.cpp (limited to 'challenge-127/deadmarshal/cpp/ch-2.cpp') diff --git a/challenge-127/deadmarshal/cpp/ch-2.cpp b/challenge-127/deadmarshal/cpp/ch-2.cpp new file mode 100644 index 0000000000..23784eb6bc --- /dev/null +++ b/challenge-127/deadmarshal/cpp/ch-2.cpp @@ -0,0 +1,37 @@ +#include +#include + +struct Interval +{ + friend std::ostream &operator<<(std::ostream &os, + const Interval &interval) + { + os << '(' << interval.x << ',' << interval.y << ')'; + return os; + } + + int x,y; +}; + +template +void conflict_intervals(const std::vector &vec) +{ + for(size_t i = 1; i < vec.size(); ++i) + { + bool b = false; + for(size_t j = 0; j < i ; ++j) + if((vec.at(i).x >= vec.at(i).x) && (vec.at(i).x <= vec.at(j).y)) b = true; + if(b) std::cout << vec.at(i) << ' '; + } + std::cout << '\n'; +} + +int main() +{ + std::vector vec1{{1,4},{3,5},{6,8},{12,13},{3,20}}; + std::vector vec2{{3,4},{5,7},{6,9},{10,12},{13,15}}; + conflict_intervals(vec1); + conflict_intervals(vec2); + return 0; +} + -- cgit