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


C++ WordList::inWordList方法代码示例

本文整理汇总了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;
            }
//.........这里部分代码省略.........
开发者ID:mossberg,项目名称:eece3326,代码行数:101,代码来源:p3b.cpp


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