From c5d362da9678bf0e410da99f957c6ad8e72e56bd Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Tue, 12 Dec 2023 15:49:30 +0000 Subject: - Added solutions by Mark Anderson. - Added solutions by Thomas Kohler. - Added solutions by Roger Bell_West. - Added solutions by Niels van Dijke. - Added solutions by Peter Campbell Smith. - Added solutions by Peter Meszaros. - Added solutions by David Ferrone. - Added solutions by W. Luis Mochan. - Added solutions by PokGoPun. - Added solutions by Laurent Rosenfeld. - Added solutions by Eric Cheung. - Added solutions by Ulrich Rieke. --- challenge-247/ulrich-rieke/cpp/ch-2.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100755 challenge-247/ulrich-rieke/cpp/ch-2.cpp (limited to 'challenge-247/ulrich-rieke/cpp/ch-2.cpp') diff --git a/challenge-247/ulrich-rieke/cpp/ch-2.cpp b/challenge-247/ulrich-rieke/cpp/ch-2.cpp new file mode 100755 index 0000000000..694cd3f0fb --- /dev/null +++ b/challenge-247/ulrich-rieke/cpp/ch-2.cpp @@ -0,0 +1,33 @@ +#include +#include +#include +#include +#include +#include + +bool mySorter( const std::pair + & p1 , const std::pair & p2 ) { + if ( p1.second != p2.second ) { + return p1.second > p2.second ; + } + else { + return p1.first < p2.first ; + } +} + +int main( ) { + std::cout << "Enter a string consisting of lowercase letters only!\n" ; + std::string line ; + std::cin >> line ; + int len = line.length( ) ; + std::map frequencies ; + for ( int pos = 0 ; pos < len - 1 ; pos++ ) { + frequencies[ line.substr( pos , 2 )]++ ; + } + std::vector> allPairs ( frequencies.begin( ) , + frequencies.end( ) ) ; + std::sort( allPairs.begin( ) , allPairs.end( ) , mySorter ) ; + std::cout << allPairs[0].first << std::endl ; + return 0 ; +} + -- cgit