-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjay9.cpp
More file actions
46 lines (43 loc) · 1.34 KB
/
jay9.cpp
File metadata and controls
46 lines (43 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
class Solution {
public:
int matchCount(string &a, string &b) {
int count = 0;
for (int i = 0; i < a.size(); i++) {
if (a[i] == b[i]) count++;
}
return count;
}
void findSecretWord(vector<string>& wordlist, Master& master) {
for (int at = 0; at < 100; at++) {
string guessWord;
if(at%2==0){
unordered_map<string,int>map1;
for(string word:wordlist){
for(string wd:wordlist){
if(matchCount(word,wd)==0){
map1[word]++;
}
}
}
int mincount=INT_MIN;
for(int i=0;i<wordlist.size();i++){
if(mincount<map1[wordlist[i]]){
mincount=map1[wordlist[i]];
guessWord=wordlist[i];
}
}}
else{
guessWord=wordlist[rand()%wordlist.size()];
}
int matches = master.guess(guessWord);
if (matches == guessWord.size()) return;
vector<string> newList;
for (auto &word : wordlist) {
if (matchCount(word, guessWord) == matches) {
newList.push_back(word);
}
}
wordlist = newList;
}
}
};