Drkcore

09 07 2008 cpp topcoder Tweet

SRM190-DIV2-500

文字当て

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 "";
  }
};

About

  • もう5年目(wishlistありマス♡)
  • 最近はPythonとDeepLearning
  • 日本酒自粛中
  • ドラムンベースからミニマルまで
  • ポケモンGOゆるめ

Tag

Python Deep Learning javascript chemoinformatics Emacs sake and more...

Ad

© kzfm 2003-2021