Write a function that compares two strings and returns a third string containing only the letters that appear in both.
Anoniem
string getcommstring(string s1,string s2) { string s; int size1 = s1.size() ; int size2 = s2.size() ; int hash[30] ; for (int i = 0 ; i < 30 ; i++) { hash[i] = 0 ; } for ( int i = 0 ; i < size1 ; i++ ) { hash[s1[i] - 'a'] = 1 ; } for (int i = 0 ; i < size2 ; i++) { if ( hash[s2[i] - 'a'] == 1 ) { s.push_back(s2[i]) ; hash[s2[i]-'a']= 0 ; } } return s ; }