当前位置: 首页>>代码示例>>C++>>正文


C++ Lexicon::containsWord方法代码示例

本文整理汇总了C++中Lexicon::containsWord方法的典型用法代码示例。如果您正苦于以下问题:C++ Lexicon::containsWord方法的具体用法?C++ Lexicon::containsWord怎么用?C++ Lexicon::containsWord使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Lexicon的用法示例。


在下文中一共展示了Lexicon::containsWord方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: sloveBoggle

Vector<string> sloveBoggle(Grid<char> &grid, Point start, int depth, Vector<Point> &path, string &word, Lexicon &lex) {
	Vector<string> result; 
	if (depth > MAX_LENGTH) {
		// greater than maxium length, return
		// return lex.containsWord(word);
	} else {
		
		//recursion to the element around the current element.
		int i = start.x;
		int j = start.y;
		if(lex.containsWord(word) && depth >= MIN_LENGTH) {
			result.add(word);
		}
		for(Direction dir = TOPLEFT; dir <= LEFT; dir++) {
			if(isBound(grid, i, j, dir)) {
				Point new_start = adjustPoint(start, dir);
				if(isContainPoint(path, new_start)) continue;
				string new_word = word + grid.getAt(new_start.x, new_start.y);
				if(!lex.containsPrefix(new_word)) continue;

				path.add(new_start);
				depth++;
				Vector<string> res = sloveBoggle(grid, new_start, depth, path, new_word, lex);
				result = concateVec(result, res);
				path.removeAt(path.size() - 1);
				depth--;
			}
		}
	} 

	return result;
}
开发者ID:kimochg,项目名称:Boggle,代码行数:32,代码来源:boggle.cpp

示例2: ListWords

int ListWords(const map<char,string> &keypads,string prex,string digitSequence,string alber,Lexicon &lex){
    int count=0;
    if(digitSequence.empty()&&lex.containsPrefix(prex)){
        if(lex.containsWord(prex)){
            count++;
            cout<<prex<<endl;
        }
        for(unsigned int i=0;i<alber.size();i++){
            string p=prex;
            p.push_back(alber[i]);
            count+=ListWords(keypads,p,digitSequence,alber,lex);
        }
        return count;
    }
    if(!digitSequence.empty()&&lex.containsPrefix(prex)){

        string nextchar=(keypads.find(digitSequence[0]))->second;
        digitSequence.erase(digitSequence.begin());
        for(unsigned int i=0;i<nextchar.size();i++){
            string p=prex;
            p.push_back(nextchar[i]);
            count+=ListWords(keypads,p,digitSequence,alber,lex);
        }
    }
    return count;
}
开发者ID:nejyeah,项目名称:cplusplus,代码行数:26,代码来源:part4.cpp

示例3: WordIsValid

bool WordIsValid(string word, Grid<string> & board, Lexicon & lex, Set<string> & wordsSeen) {
	if (word.length() < 4) {
		return false;
	} else if (wordsSeen.contains(word)) {		//already seen the word
		return false;	
	} else if (!lex.containsWord(word)) {		//not a word according to the dictionary
		return false;
	} else {
		Vector<locationT> empty;
		Vector<Vector<locationT> > results;
		Findable(board, word, -1, -1, empty, results);
		if (results.size() == 0) {							//no paths were found for the word, so word can't be found
			return false;
		} else {
			Vector<locationT> answer = results[0];			//at least one path was found, so return true and highlight the cubes
			for (int i = 0; i < answer.size(); i++) {
				HighlightCube(answer[i].numRow, answer[i].numCol, true);
			}
			Pause(.5);
			for (int i = 0; i < answer.size(); i++) {		//then un-highlight the cubes
				HighlightCube(answer[i].numRow, answer[i].numCol, false);
			}
			return true;
		}
	}
}
开发者ID:gdcohan,项目名称:Boggle,代码行数:26,代码来源:boggle.cpp

示例4: printValidWords

// checks lexicon and prints all words that begin with the given prefix
void printValidWords(string prefix, Lexicon &lex){
    string alpha = "abcdefghijklmnopqrstuvwxyz";
    if(lex.containsWord(prefix)) cout << prefix << " ";

    if(lex.containsPrefix(prefix)){
        for(int i = 0; i < alpha.length(); i++){
            printValidWords(prefix + alpha.at(i), lex);
        } 
    }
}
开发者ID:brianjscoles,项目名称:CS106b-solutions,代码行数:11,代码来源:4+-+keypad+words.cpp

示例5: FindWordsOnBoard

/*
 * Function: FindWordsonBoard
 * ------------------------------
 * Recursively searchs for all possible words that can be created from dice configuration of boggleBoard starting from
 * the specified location.
 *
 *@return bool	true if the char arrangement found is an actual word.
 *				false if all possibilities have been exhausted and no word is created.
 */
bool FindWordsOnBoard(Grid<char> boggleBoard, int row, int col, string partialWord, Grid<bool> usedDice, Lexicon wordList, Lexicon &usedWords)
{	
	int newRow, newCol;
	if (OffBoard(boggleBoard, row, col) || usedDice.getAt(row, col) == true) return false; 
	partialWord += boggleBoard.getAt(row, col); //keeps track of current char arrangement
	if (!wordList.containsPrefix(partialWord)) return false; //checks if partialWord is a prefix of any word in wordList
	usedDice.setAt(row, col, true); //marks the dice as used
	if (wordList.containsWord(partialWord) && partialWord.length() >= minWordLength && !usedWords.containsWord(partialWord)) {
        //checks if partialWord is an actual word meeting the minimum length and has not been used by either the player or computer
		RecordWordForPlayer(partialWord, Computer);
		usedWords.add(partialWord); //adds the word found to list of used words
	}
	for(int i = 0; i < 8; i++) { //there are 8 possible paths the char arrangement can take
		FindPossiblePath(newRow, newCol, row, col, i);
		if (FindWordsOnBoard(boggleBoard, newRow, newCol, partialWord, usedDice, wordList, usedWords)) return true;
	}
	usedDice.setAt(row, col, false); //unmarks the dice as unused when current char configuration turns out fruitless
	return false;
}
开发者ID:ruiping82,项目名称:Stanford,代码行数:28,代码来源:boggle.cpp

示例6: CheckUserGuess

/*
 * Function: CheckUserGuess
 * ---------------------------
 * Checks if the format of user guess meets all requirements of the boggle rules.
 *
 *@return string userGuess when function has confirmed that all requirements have been met.
 */
string CheckUserGuess(Lexicon wordList, Lexicon usedWords)
{
	while (true) { //prompts until appropriate guess is received
		cout << "Enter a word: ";
		string userGuess = ConvertToUpperCase(GetLine());
		if (userGuess == "") return "";
		if (userGuess.length() < minWordLength) { //checks if minimum word length is met
			cout << "I'm sorry, but we have our standards." << endl;
			cout << "That word doesn't meet the minimum word length of 4." << endl;
			PlayNamedSound("whoops.wav");
		} else if (!wordList.containsWord(userGuess)) { //checks if the guess is actually a word
			cout << "That's not a word! " << RandomizeResponse() << endl;
			PlayNamedSound("whoops.wav");
		} else if (usedWords.containsWord(userGuess)) { //checks if the guess has already been used
			cout << "You've already guessed that! " << RandomizeResponse() << endl;
			PlayNamedSound("whoops.wav");
		} else {
			return userGuess;
		}
	}
}
开发者ID:ruiping82,项目名称:Stanford,代码行数:28,代码来源:boggle.cpp

示例7: getCompletions

/**
 *  @brief Gets possible completions for a given word
 *  @param word The word to check for completions
 *  @param lex The lexicon to check completions against
 *  @param words A set that will be filled with possible completions
 *
 *  This function recursively checks for possible completions of a given
 *  word, using the provided lexicon.
 */
void getCompletions(string word, Lexicon &lex, Set<string> &words)
{
    if (lex.containsWord(word)) {
        words.add(word);
    }

    for (int i = 0; i < ALPHABET.size(); i++) {
        string newWord = word + ALPHABET[i];
        if (lex.containsPrefix(newWord)) {
            getCompletions(newWord, lex, words);
        }
    }
}
开发者ID:ravero,项目名称:CS106B,代码行数:22,代码来源:main.cpp

示例8: verifyGuess

bool verifyGuess(string &guess, Grid<char> &grid, Lexicon &lex) {
	guess = ConvertToUpperCase(guess);
	if(!lex.containsWord(guess)) return false;
	Vector<Point> starts = getStartPoints(guess[0], grid);
	Vector<string> humVec,humVecTotal;
	string word = "";
	Vector<Point> path;
	for (int i = 0; i < starts.size(); i++) {
		Point start = starts.getAt(i);
		path.clear();
		path.add(start);
		word = "";
		word += grid.getAt(start.x, start.y);
		humVec = sloveBoggle(grid, start, 1, path, word, lex);
		humVecTotal = concateVec(humVecTotal, humVec);
	}
	return isContainWord(humVecTotal, guess);
}
开发者ID:kimochg,项目名称:Boggle,代码行数:18,代码来源:boggle.cpp

示例9: FindAllWords

void FindAllWords(int row, int col, Grid<string> & board, Lexicon & lex, Set<string> & wordsSeen, string soFar, Vector<locationT> visited) {
	locationT here;
	here.numRow = row;
	here.numCol = col;
	visited.add(here);							
	soFar += board(row,col);					
	if (!lex.containsPrefix(soFar)) {			//return if this is a dead end
		return;
	}
	if (lex.containsWord(soFar) && (!wordsSeen.contains(soFar)) && soFar.size() > 3) {
		RecordWordForPlayer(soFar, Computer);			//found a word, so record it
		wordsSeen.add(soFar);
	}
	for (int i = 0; i < board.numRows(); i++) {
		for (int j = 0; j < board.numCols(); j++) {
			if (AreNeighbors(row, col, i, j) && NotDuplicated(i, j, visited)) {		//recur on the rest of the puzzle for all 
				FindAllWords(i, j, board, lex, wordsSeen, soFar, visited);			//neighbors that haven't already been seen
			}
		}
	}
}
开发者ID:gdcohan,项目名称:Boggle,代码行数:21,代码来源:boggle.cpp

示例10: validWord

bool validWord(string s, Lexicon &lex) { return lex.containsWord(s); } 
开发者ID:azavadil,项目名称:portfolio,代码行数:1,代码来源:boggle.cpp


注:本文中的Lexicon::containsWord方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。