jeniljain29392
BAN USERPython solution:
words = ["baa", "caan", "cann", "ba", "cab", "noob"]
chars = ["b", "a", "c", "n"]
for word in words:
temp = list(chars)
if len(word) > len(chars):
continue
for char in word:
if char not in temp:
break
else:
temp.remove(char)
if len(chars) - len(word) == len(temp):
print word
C++ solution:
int main() {
string words[] = {"baa", "caan", "cann", "ba", "cab", "noob"};
char chars[] = {'b', 'a', 'c', 'n', 'a'};
multiset<char> vchar;
for(char x : chars)
vchar.insert(x);
for(string word : words){
multiset<char> temp(vchar);
if(word.size() > temp.size()){
continue;
}
for(char c : word){
if(temp.find(c) == temp.end())
break;
else
temp.erase(temp.find(c));
}
if(vchar.size() - word.size() == temp.size())
cout<<word<<endl;
}
return 0;
}
Python
c++ Solution
- jeniljain29392 May 13, 2016