diff options
Diffstat (limited to 'challenge-282/ulrich-rieke/cpp/ch-2.cpp')
| -rwxr-xr-x | challenge-282/ulrich-rieke/cpp/ch-2.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/challenge-282/ulrich-rieke/cpp/ch-2.cpp b/challenge-282/ulrich-rieke/cpp/ch-2.cpp new file mode 100755 index 0000000000..e60fe3f932 --- /dev/null +++ b/challenge-282/ulrich-rieke/cpp/ch-2.cpp @@ -0,0 +1,29 @@ +#include <iostream>
+#include <string>
+#include <cctype>
+#include <algorithm>
+#include <vector>
+
+std::string to_lower( std::string aWord ) {
+ std::transform( aWord.begin( ) , aWord.end( ) , aWord.begin( ) ,
+ tolower ) ;
+ return aWord ;
+}
+
+int main( ) {
+ std::cout << "Please enter an alphabetic word!\n" ;
+ std::string word ;
+ std::cin >> word ;
+ int pos = 0 ;
+ std::vector<std::string> pairs ;
+ while ( pos < word.length( ) - 2 ) {
+ pairs.push_back( word.substr( pos , 2 ) ) ;
+ pairs.push_back( word.substr( pos + 1 , 2 ) ) ;
+ pos += 2 ;
+ }
+ std::transform( pairs.begin( ) , pairs.end( ) , pairs.begin( ) ,
+ to_lower ) ;
+ std::cout << std::count_if( pairs.begin( ) , pairs.end( ) , []( const
+ auto & s ) { return s.at( 0 ) != s.at( 1 ) ; }) << '\n' ;
+ return 0 ;
+}
|
