Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * // This is the Master's API interface.
- * // You should not implement it, or speculate about its implementation
- * class Master {
- * public:
- * int guess(string word);
- * };
- */
- class Solution {
- int overlap(string s1, string s2){
- // always -> s1.length = s2.length = 6;
- //return the number of overlapping letters in s1 and s2
- int overlapLength = 0;
- for(int i = 0; i<=5; i++){
- if(s1[i] == s2[i]){
- overlapLength++;
- }
- }
- return overlapLength;
- }
- public:
- void findSecretWord(vector<string>& wordList, Master& master) {
- unordered_set<string> words;
- for(auto &x: wordList){
- words.insert(x);
- }
- while(!words.empty()){
- string guessedWord = *(words.begin());
- int x = master.guess(guessedWord);
- //cout << guessedWord << " - " << x << endl;
- if(x==6){
- return;
- }
- words.erase(guessedWord);
- if(x == 0){
- unordered_set<string> dup(words.begin(), words.end());
- for(auto &word: dup){
- if(overlap(word, guessedWord) > 0){
- words.erase(word);
- }
- }
- }
- else if(x > 0){
- unordered_set<string> dup(words.begin(), words.end());
- for(auto &word: dup){
- if(overlap(word, guessedWord) < x){
- words.erase(word);
- }
- }
- }
- }
- }
- };
- // Suppose we guess a random word r:
- // x = master.guess(r);
- // if(x == 0){
- // //cross out all the words that have overlapLength > 0 with r...
- // //guesss agian
- // }
- // if(x > 0){
- // //cross out all the words that have overlapLength < x with r;
- // }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement