From 061fd6e6c13501a82c05dc2d8e989ed0c28c212b Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Fri, 2 Sep 2022 17:19:50 +0100 Subject: - Added guest contributions by Humberto Massa. --- challenge-180/massa/cpp/ch-1.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 challenge-180/massa/cpp/ch-1.cpp (limited to 'challenge-180/massa/cpp/ch-1.cpp') diff --git a/challenge-180/massa/cpp/ch-1.cpp b/challenge-180/massa/cpp/ch-1.cpp new file mode 100644 index 0000000000..f6e69de7f2 --- /dev/null +++ b/challenge-180/massa/cpp/ch-1.cpp @@ -0,0 +1,25 @@ + +#include +#include +#include +#include + +template S> +It first_unique(It begin, S end) { + for( auto it = begin; it != end; ++it ) + if( std::find(begin, it, *it) == it && std::find(it+1, end, *it) == end ) + return it; + return end; +} + +auto first_unique(std::ranges::input_range auto range) { + return first_unique(begin(range), end(range)); +} + +int main(int argc, char **argv) { + for( std::string_view a: std::span { argv+1, argv+argc } ) { + auto u = first_unique(a); + std::cout << (u == std::end(a) ? -1 : u - std::begin(a)) << ' ' << a << '\n'; + } +} + -- cgit