Esempio n. 1
0
int main(int argv, char *argc){
	int i = 0,
		len = 0,
		lenSentence = 0,
		flag = 0;
	char sentence[WORD*WORDS];
	char ch;
	
	while((ch = getchar()) != '\n'){
		if(ch != ' '){
			flag = 0;
			sentence[i] = ch;
			i++;
			len++;
		}
		else if(flag == 0){
			flag = 1;
			sentence[i] = ch;
			i++;
			len++;
		}
	}

	lenSentence = checkSentence(len, sentence);
	checkWord(lenSentence, sentence);
	checkWords(lenSentence, sentence);
	printWords(lenSentence, sentence);

	system("PAUSE");
	return 0;
}
Esempio n. 2
0
void Solution::checkWords(vector<vector<char> > &board, int i, int j, int row, int col, Trie *root, vector<string> &res, vector<string> &words)
{
	char temp;
	if(board[i][j]=='X') return; // visited before;
	if(nullptr == root->children[board[i][j]-'a']) return ; // no string with such prefix
	else
	{
		temp = board[i][j];
		if(root->children[temp-'a']->leaf)  // if it is a leaf
		{
			res.push_back(words[root->children[temp-'a']->idx]);
			root->children[temp-'a']->leaf = false; // set to false to indicate that we found it already
		}
		board[i][j]='X'; //mark the current position as visited
		// check all the possible neighbors
		if(i>0) checkWords(board, i-1, j, row, col, root->children[temp-'a'], res, words);
		if((i+1)<row) checkWords(board, i+1, j, row, col,  root->children[temp-'a'], res, words);
		if(j>0) checkWords(board, i, j-1,  row, col, root->children[temp-'a'], res, words);
		if((j+1)<col)  checkWords(board, i, j+1,  row, col, root->children[temp-'a'], res, words);
		board[i][j] = temp; // recover the current position
	}
}
Esempio n. 3
0
void MainWindow::on_stopBut_clicked()
{
	elpsd = myTimer.elapsed();
    elpsd /= 1000;
    ui->stopBut->setDisabled(true);
    ui->enterText->setReadOnly(true);
    ui->startBut->setFocus();
    int cnt = checkWords();
    if (cnt)
        ui->messageText->setText("You wrote at the rate of\n" + QString::number(60.0 * cnt / elpsd)+" words per minute");
    else
        if (elpsd)
            ui->messageText->setText("You did not write since " + QString::number(elpsd) + (elpsd > 1 ? " seconds" : " second"));
        else
            ui->messageText->setText("Better test your typing speed");
}
Esempio n. 4
0
vector<string> Solution::findWords(vector<vector<char> > &board, vector<string> &words)
{
	vector<string> res;
	int row = board.size();
	if(0==row) return res;
	int col = board[0].size();
	if(0==col) return res;
	int wordCount = words.size();
	if(0==wordCount) return res;
	
	Trie *root = buildTrie(words);
	
	int i,j;
	for(i =0 ; i<row; i++)
	{
		for(j=0; j<col && wordCount > res.size(); j++)
		{
			checkWords(board, i, j, row, col, root, res, words);
		}
	}
	return res;
}
Esempio n. 5
0
bool compareWords(diff_edit& e1, diff_edit& e2, const DocLines_t& doc1, const DocLines_t& doc2, bool IgnoreSpaces)
{
	unsigned int i, j;

	chunk_info chunk1(e1.off, e1.len);
	chunk_info chunk2(e2.off, e2.len);

	getWords(doc1, chunk1, IgnoreSpaces);
	getWords(doc2, chunk2, IgnoreSpaces);

	// Compare the two chunks
	std::vector<diff_edit> diff = DiffCalc<Word>(chunk1.words, chunk2.words)();

	chunk1.changes.reset(new varray<diff_change>);
	chunk2.changes.reset(new varray<diff_change>);

	std::vector<std::vector<int>> lineMappings1(chunk1.lineCount);

	for (i = 0; i < chunk1.lineCount; ++i)
		lineMappings1[i].resize(chunk2.lineCount, 0);

	// Use the MATCH results to synchronize line numbers
	// count how many are on each line, then select the line with the most matches
	const std::size_t diffSize = diff.size();

	int offset = 0;
	for (i = 0; i < diffSize; ++i)
	{
		diff_edit& e = diff[i];

		if (e.op == DIFF_DELETE)
		{
			offset -= e.len;
		}
		else if (e.op == DIFF_INSERT)
		{
			offset += e.len;
		}
		else
		{
			for (unsigned int index = e.off; index < (e.off + e.len); ++index)
			{
				Word *word1 = &chunk1.words[index];
				Word *word2 = &chunk2.words[index + offset];

				if (word1->type != SPACECHAR && word1->type != EOLCHAR)
				{
					int line1a = word1->line;
					int line2a = word2->line;
					lineMappings1[line1a][line2a] += word1->length;
				}
			}
		}
	}

	// go through each line, and select the line with the highest strength
	for (i = 0; i < chunk1.lineCount; ++i)
	{
		int line = -1;
		int max = 0;

		for (j = 0; j <chunk2.lineCount; ++j)
		{
			if (lineMappings1[i][j] > max && (e2.moves.empty() || e2.moves[j] == -1))
			{
				line = j;
				max = lineMappings1[i][j];
			}
		}

		// make sure that the line isn't already matched to another line,
		// and that enough of the line is matched to be significant
		const int size = doc1[e1.off + i].size();

		if (line != -1 && chunk2.lineMappings[line] == -1 && max > (size / 3) &&
				(e1.moves.empty() || e1.moves[i] == -1))
		{
			chunk1.lineMappings[i] = line;
			chunk2.lineMappings[line] = i;
		}
	}

	// find all the differences between the lines
	chunk1.changeCount = 0;
	chunk2.changeCount = 0;

	for (i = 0; i < diffSize; ++i)
	{
		diff_edit& e = diff[i];

		if (e.op == DIFF_DELETE)
		{
			// Differences for Doc 1
			checkWords(e, chunk1, chunk2);
		}
		else if (e.op == DIFF_INSERT)
		{
			// Differences for Doc2
			checkWords(e, chunk2, chunk1);
		}
	}

	e1.changeCount = chunk1.changeCount;
	e1.changes = chunk1.changes;
	e2.changeCount = chunk2.changeCount;
	e2.changes = chunk2.changes;

	return (chunk1.changeCount + chunk2.changeCount > 0);
}
Esempio n. 6
0
void MainWindow::refresh_clicked()
{
    if(!checked)
    {
        if(ui->spanishRB->isChecked())
        {
            ui->slovak_label->setText(slovak.at(randNum));

            QString slovakWord = slovak.at(randNum);
            QString slovakTranslation = ui->slovak_lineEdit->text();
            bool equal;
            if(slovakWord.contains(";")) // sklada sa z viacerych slov
            {
                QStringList wordList; wordList = slovakWord.split(";");

                QListIterator<QString> iter(wordList);
                while(iter.hasNext())
                {
                    QString word = iter.next();
                    equal = checkWords(slovakTranslation, word);
                    if(equal) break;
                }
            }
            else
            {
                equal = checkWords(slovakTranslation, slovakWord);
            }

            if(equal)
            {
                ui->slovak_label->setStyleSheet("QLabel {color : green; }");

                int correct = ui->correctLabel->text().toInt();
                ui->correctLabel->setText(QString::number(correct + 1));
                ui->correctLabel->setStyleSheet("QLabel {color : green; }");
            }
            else
            {
                ui->slovak_label->setStyleSheet("QLabel {color : red; }");
                ui->correctLabel->setText("0");
                ui->correctLabel->setStyleSheet("QLabel {color : red; }");
            }
        }
        else if(ui->slovakRB->isChecked())
        {
            ui->spanish_label->setText(spanish.at(randNum));

            QString spanishWord = spanish.at(randNum);
            QString spanishTranslation = ui->spanish_lineEdit->text();
            bool equal;
            if(spanishWord.contains(";")) // sklada sa z viacerych slov
            {
                QStringList wordList; wordList = spanishWord.split(";");

                QListIterator<QString> iter(wordList);
                while(iter.hasNext())
                {
                    QString word = iter.next();
                    equal = checkWords(spanishTranslation, word);
                    if(equal) break;
                }
            }
            else
            {
                equal = checkWords(spanishTranslation, spanishWord);
            }

            if(equal)
            {
                ui->spanish_label->setStyleSheet("QLabel {color : green; }");
                int correct = ui->correctLabel->text().toInt();
                ui->correctLabel->setText(QString::number(correct + 1));
                ui->correctLabel->setStyleSheet("QLabel {color : green; }");
            }
            else
            {
                ui->spanish_label->setStyleSheet("QLabel {color : red; }");
                ui->correctLabel->setText("0");
                ui->correctLabel->setStyleSheet("QLabel {color : red; }");
            }
        }

        checked = true;
    }
    else
    {
        randNum = random(0, vocabLen);
        ui->spanish_label->clear();
        ui->slovak_label->clear();

        if(ui->spanishRB->isChecked())
        {
            ui->slovak_lineEdit->clear();
            ui->spanish_lineEdit->setText(spanish.at(randNum));
        }
        else if(ui->slovakRB->isChecked())
        {
            ui->spanish_lineEdit->clear();
            ui->slovak_lineEdit->setText(slovak.at(randNum));
        }

        checked = false;
    }
}