countメソッドを覚えたのでメモ。
class Hangman {
public:
string guessWord(string feedback, vector <string> words) {
vector <string> candidates;
for(int i=0;i<words.size();i++) {
if(words[i].length() == feedback.length()) {
vector <char> used,fused;
int mismatched =0;
for(int j=0;j<feedback.length();j++) {
if(feedback[j] != '-' && feedback[j] != words[i][j]) {
mismatched++;
}
else if (feedback[j] != '-' && feedback[j] == words[i][j]) {
int fc = (int) count(feedback.begin(), feedback.end(), feedback[j]);
int wc = (int) count(words[i].begin(), words[i].end(), feedback[j]);
if (fc != wc) mismatched++;
}
}
if(mismatched>0) continue;
candidates.push_back(words[i]);
}
}
if (candidates.size() == 1) return candidates[0];
else return "";
}
};