#include #include #include #include #include std::vector split( const std::string & text , char delimiter ) { std::vector tokens ; std::istringstream istr { text } ; std::string word ; while ( std::getline( istr , word , delimiter ) ) { tokens.push_back( word ) ; } return tokens ; } int main( ) { std::cout << "Enter some words separated by whitespace!\n" ; std::string line ; std::getline( std::cin , line ) ; auto firstTokens { split( line , ' ' ) } ; std::string secondline ; std::cout << "Enter some more words separated by whitespace!\n" ; std::getline( std::cin , secondline ) ; auto secondTokens { split( secondline , ' ' ) } ; std::map firstFrequency , secondFrequency ; int common = 0 ; for ( auto s : firstTokens ) firstFrequency[s]++ ; for ( auto s : secondTokens ) secondFrequency[s]++ ; for ( auto aPair : firstFrequency ) { if ( secondFrequency.find( aPair.first ) != secondFrequency.end( ) ) { common++ ; } } std::cout << common << '\n' ; return 0 ; }