aboutsummaryrefslogtreecommitdiff
path: root/challenge-247/ulrich-rieke/cpp/ch-2.cpp
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2023-12-12 15:49:30 +0000
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2023-12-12 15:49:30 +0000
commitc5d362da9678bf0e410da99f957c6ad8e72e56bd (patch)
tree6ad038a2987222b9e1a9c18b1307f688a810602c /challenge-247/ulrich-rieke/cpp/ch-2.cpp
parent024ced642f56003a51fe61164cdc9598219c3f4d (diff)
downloadperlweeklychallenge-club-c5d362da9678bf0e410da99f957c6ad8e72e56bd.tar.gz
perlweeklychallenge-club-c5d362da9678bf0e410da99f957c6ad8e72e56bd.tar.bz2
perlweeklychallenge-club-c5d362da9678bf0e410da99f957c6ad8e72e56bd.zip
- 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.
Diffstat (limited to 'challenge-247/ulrich-rieke/cpp/ch-2.cpp')
-rwxr-xr-xchallenge-247/ulrich-rieke/cpp/ch-2.cpp33
1 files changed, 33 insertions, 0 deletions
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 <vector>
+#include <iostream>
+#include <algorithm>
+#include <utility>
+#include <string>
+#include <map>
+
+bool mySorter( const std::pair<std::string , int>
+ & p1 , const std::pair<std::string , int> & 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<std::string , int> frequencies ;
+ for ( int pos = 0 ; pos < len - 1 ; pos++ ) {
+ frequencies[ line.substr( pos , 2 )]++ ;
+ }
+ std::vector<std::pair<std::string , int>> allPairs ( frequencies.begin( ) ,
+ frequencies.end( ) ) ;
+ std::sort( allPairs.begin( ) , allPairs.end( ) , mySorter ) ;
+ std::cout << allPairs[0].first << std::endl ;
+ return 0 ;
+}
+