#include #include #include #include using namespace std ; //Find the groups of anagrams in the vector of strings //You can sort a string by using the following code // sort( str1.begin() , str1.end() ) int getGroupNumber( vector& v1 ) { map< string, int> map1 ; int result = 0 ; for( string str1 : v1 ) { sort( str1.begin() , str1.end() ) ; //cout << str1 << endl ; if ( map1.count( str1 ) > 0 ) { map1[ str1 ] = 1 ; } else { map1[ str1 ] = 0 ; } } // for( pair pair1 : map1 ) { if ( pair1.second == 1 ) result++ ; } return result ; } int main () { vector v1 = { "cinema" , "iceman" , "the" } ; cout << getGroupNumber( v1 ) << endl ; vector v2 = { "cinema" , "iceman" , "the" , "nat", "tan" } ; cout << getGroupNumber( v2 ) << endl ; return 0; }