本文整理汇总了C++中WordList::inWordList方法的典型用法代码示例。如果您正苦于以下问题:C++ WordList::inWordList方法的具体用法?C++ WordList::inWordList怎么用?C++ WordList::inWordList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WordList
的用法示例。
在下文中一共展示了WordList::inWordList方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: checkNext
void checkNext(const int DIRECTION, const WordList &list, const matrix<char> &grid, int i, int j)
// given a direction, a word list, a matrix, and starting coordinates,
// append characters and search for the new word in the word list
// prints out word if found in list
{
if (i < 0 || j < 0)
throw baseException("invalid grid coordinates");
int grid_rows = grid.rows() - 1;
int grid_cols = grid.cols() - 1;
// the coordinates to actually search at
int x = j;
int y = i;
string word;
word.push_back(grid[i][j]);
// update coordinates
switch (DIRECTION)
{
case NORTH:
y = y - 1; // move y to where we're going to look
if (y < 0) // check if exceeded grid bounds
y = grid_rows; // if so, move to bottom row
while (y != i)
{
word.push_back(grid[y][x]);
if(list.inWordList(word))
cout << word << endl;
y = y - 1; // move y to where we're going to look
if (y < 0) // check if exceeded grid bounds
y = grid_rows; // if so, move to bottom row
}
break;
case NORTHEAST:
y = y - 1;
x = x + 1;
if (y < 0) y = grid_rows;
if (x > grid_cols) x = 0;
while (x != j && y != i)
{
word.push_back(grid[y][x]);
if(list.inWordList(word))
cout << word << endl;
y = y - 1;
x = x + 1;
if (y < 0) y = grid_rows;
if (x > grid_cols) x = 0;
}
break;
case EAST:
x = x + 1;
if (x > grid_cols) x = 0;
while (x != j)
{
word.push_back(grid[y][x]);
if(list.inWordList(word))
cout << word << endl;
x = x + 1;
if (x > grid_cols) x = 0;
}
break;
case SOUTHEAST:
y = y + 1;
x = x + 1;
if (y > grid_rows) y = 0;
if (x > grid_cols) x = 0;
while (x != j && y != i)
{
word.push_back(grid[y][x]);
if(list.inWordList(word))
cout << word << endl;
y = y + 1;
x = x + 1;
if (y > grid_rows) y = 0;
if (x > grid_cols) x = 0;
}
break;
case SOUTH:
y = y + 1;
if (y > grid_rows) y = 0;
while (y != i)
{
word.push_back(grid[y][x]);
if(list.inWordList(word))
cout << word << endl;
y = y + 1;
if (y > grid_rows) y = 0;
}
//.........这里部分代码省略.........