From fefc7c358edfe567b1444cb88caed7738c4eb4fe Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Tue, 13 Dec 2022 12:30:19 +0000 Subject: - Added solutions by Luca Ferrari. - Added solutions by David Ferrone. - Added solutions by Dave Jacoby. - Added solutions by Mark Anderson. - Added solutions by Thomas Kohler. - Added solutions by Robert Ransbottom. - Added solutions by W. Luis Mochan. - Added solutions by Ulrich Rieke. - Added solutions by Olivier Delouya. - Added solutions by Robert DiCicco. --- challenge-195/ulrich-rieke/cpp/ch-1.cpp | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 challenge-195/ulrich-rieke/cpp/ch-1.cpp (limited to 'challenge-195/ulrich-rieke/cpp/ch-1.cpp') diff --git a/challenge-195/ulrich-rieke/cpp/ch-1.cpp b/challenge-195/ulrich-rieke/cpp/ch-1.cpp new file mode 100644 index 0000000000..0d6fcd8ac6 --- /dev/null +++ b/challenge-195/ulrich-rieke/cpp/ch-1.cpp @@ -0,0 +1,35 @@ +#include +#include +#include +#include +#include +#include + +bool isSpecial( int n ) { + if ( n < 10 ) { + return true ; + } + else { + std::map frequencies ; + while ( n != 0 ) { + frequencies[ n % 10]++ ; + n /= 10 ; + } + std::vector> allPairs( frequencies.begin( ) , + frequencies.end( ) ) ; + return std::all_of( allPairs.begin( ) , allPairs.end( ) , [] ( auto & + p ) { return p.second == 1 ; } ) ; + } +} + +int main( int argc , char * argv[] ) { + int num = std::atoi( argv[1] ) ; + int count = 0 ; + for ( int i = 1 ; i < num + 1 ; i++ ) { + if ( isSpecial( i ) ) { + count++ ; + } + } + std::cout << count << std::endl ; + return 0 ; +} -- cgit