Ejemplo n.º 1
0
 void searchWords(vector<vector<char>>& board, int i, int j, string str, TrieNode* node){
     node = node->dic[board[i][j] - 'a'];
     if (node){
         str.push_back(board[i][j]);
         if (node->isWord && std::find(res.begin(), res.end(), str) == res.end()) {
             res.push_back(str);
         }
         char tmp = board[i][j];
         board[i][j] = 0;
         if (i > 0 && board[i-1][j]) searchWords(board, i-1, j, str, node);
         if (i < m - 1 && board[i+1][j]) searchWords(board, i+1, j, str, node);
         if (j > 0 && board[i][j-1]) searchWords(board, i, j-1, str, node);
         if (j < n - 1 && board[i][j+1]) searchWords(board, i, j+1, str, node);
         board[i][j] = tmp;
     }
 }
Ejemplo n.º 2
0
WordContainer* Anagrabber::getWords(string input)
{
	wordToSolve = input;
	WordContainer* wordList = new WordContainer();
	wordFinder = new WordsIndex(wordToSolve);
	searchWords(*wordList);
	delete wordFinder;
	return wordList;
}
Ejemplo n.º 3
0
int main()
{
  Trie Root;
  Root =initializeTrie(Root);
  Root= addwords(Root ,"sairam");
  Root =addwords(Root,"surfeit");
  Root =addwords(Root,"hello");
  if(!searchWords(Root,"sairam"))
    printf("does not exist\n");
  else
    printf("it does\n");  
return 0;
}
Ejemplo n.º 4
0
int  searchWords(Trie Root, char* words)
{ int t;
   if(words[0]=='\0')
   return 1;
   else
   {
	t = words[0]-'a';
	if(Root->edges[t]==NULL)
	 return 0;
	else
	return searchWords(Root->edges[t],++words) ;
   }
}
Ejemplo n.º 5
0
bool FiruMainWindow::setDirection( Lang src, Lang trg, bool reverse )
{
    m_dictionary = Dictionary::Ptr( new Dictionary( LangPair( src, trg ) ) );
    if ( m_dictionary->open() )
    {
        m_reverse = reverse;
        updateDirectionLabels();
        m_totalWords = m_dictionary->count( "" );
        m_ui.editInput->clear();
        searchWords();
        return true;
    }
    return false;
}
Ejemplo n.º 6
0
FiruMainWindow::FiruMainWindow( QWidget *parent )
    : QMainWindow( parent ), 
    m_reverse( false ), 
    m_loadTimer( this ),
    m_totalWords( 0 )
{
	m_ui.setupUi(this);

#ifndef Q_OS_DARWIN
    menuBar()->addAction( m_ui.actionOpenDict );
    menuBar()->addAction( m_ui.actionOpenTrainer );
//    menuBar()->addAction( m_ui.actionSearch_reverse );
    menuBar()->addAction( m_ui.actionRebuild_Hashes );
    menuBar()->addAction( m_ui.actionResetMarks );
#else
    QMenu* fileMenu = menuBar()->addMenu("File");
    fileMenu->addAction( m_ui.actionOpenDict );
    fileMenu->addAction( m_ui.actionOpenTrainer );
//    menuBar->addAction( m_ui.actionSearch_reverse );
    fileMenu->addAction( m_ui.actionRebuild_Hashes );
    fileMenu->addAction( m_ui.actionResetMarks );
#endif

#ifdef __SYMBIAN32__
    showMaximized();
#else
    QRect rect = m_appUi.GetClientRect();
    setGeometry( rect );
#endif

    m_ui.listSources->installEventFilter( this );
    m_ui.editInput->installEventFilter( this );
    m_ui.progressBar->hide();
    m_ui.laWordCount->hide();
    
    m_loadTimer.setSingleShot( true );
    m_loadTimer.setInterval( 1000 );
    
    connect( 
        m_ui.editInput, SIGNAL( textChanged( const QString& ) ), 
        this, SLOT( onPatternChanged( const QString& ) ) );

    connect( 
        &m_loadTimer, SIGNAL( timeout() ), 
        this, SLOT( searchWords() ) );

    setDirection( QLocale::Finnish, QLocale::Russian );
}
Ejemplo n.º 7
0
 vector<string> findWords(vector<vector<char>>& board, vector<string>& words) {
     res.clear();
     if (words.size() == 0 || board.size() == 0){
         return res;
     }
     m = board.size();
     n = board[0].size();
     len = words.size();
     if (n){
         trie = *(new Trie());
         for (int i = 0; i < len; i++){
             trie.insert(words[i]);
         }
         string str = "";
         for (int i = 0; i < m; i++){
             for (int j = 0; j < n; j++){
                 searchWords(board, i, j, str, trie.root);
             }
         }
     }
     
     return res;
 }