Beispiel #1
0
int main(int argc, char **argv)
{	max_x=max_y=min_x=min_y=MID;

	readDictionary(*argv +1);
	ws_maker();
	setlastFour();
	getMaxAndMin_X_Y();
	if(debug)
	for(int i=0; i<MAXMATRIX; i++){
		for(int j=0; j<MAXMATRIX; j++)
			printf("%C",Word[i][j]);
		printf("\n");
	}
	FILE *h;
	h = fopen("answer.txt", "w+");
	for(int i=0; i<max_x - min_x +1 ; i++){
		for(int j=0; j<max_y - min_y +1; j++){
			answer[i][j] = Word[min_x+i][min_y+j];
			if(answer[i][j] == 0)
				answer[i][j] = 'Z';
			printf("%c ", answer[i][j]);
			fputc(answer[i][j],h);
		}
		printf("\n");
		fputc('\n',h);
	}


	printf("%d %d %d %d\n",max_x ,min_x, max_y ,min_y);

}
Beispiel #2
0
/**
Funkcja otwierajaca plik z rozszerzeniem dt
@param name nazwa otwieranego pliku
@param name_save nazwa pliku wynikowego
 */
void Reader::open(string name,string name_save){



    size_t found = name.find(".dt");

    if(found==-1)
    {
        name = name + ".dt";
    }

    char *nazwa= new char[name.length()+1];
    strcpy( nazwa, name.c_str() );

    plik.open( nazwa, ios::in|ios::binary);
    if( plik.good() == true )
    {
        // wczytanie width
        plik.seekg( 0,ios::beg );
        int length =24;
        char * buffer = new char [length];
        plik.read(buffer,length);
        string helpReader;
        helpReader =charToString(buffer,length);
        width=bin2dec(helpReader);
        // end of width
        //wczytanie height
        plik.read(buffer,length);
        helpReader =charToString(buffer,length);

        height=bin2dec(helpReader);
        //end of height
        //wczytanie pixelWidth
        plik.read(buffer,length);
        helpReader =charToString(buffer,length);
        pixelWidth=bin2dec(helpReader);
        //end of pixelWidth
        //wczytaniey
        length =16;
        buffer = new char [length];
        plik.read(buffer,length);
        helpReader =charToString(buffer,length);
        dictionaryStart=bin2dec(helpReader);
        // endo of dictionaryStart
        //wczytanie pictureStart
        plik.read(buffer,length);
        helpReader =charToString(buffer,length);
        pictureStart=bin2dec(helpReader);
        ///end of pictureStart

        screen = SDL_SetVideoMode(width, height,32,SDL_RESIZABLE|SDL_DOUBLEBUF);

        readDictionary(name_save);

    }

    plik.close();


}
Beispiel #3
0
void jccTest(char *dictionary, char *phoneBook, char *output)
/* jccTest - Test program.. */
{
int maxSize;
struct hash *hash = readDictionary(dictionary, &maxSize);
processPhoneBook(hash, maxSize, phoneBook, output);
}
int main(int argc, char *argv[]) {
  readDictionary();
  size_t tam;
  std::ifstream fileStream(argv[1]);
  if (!fileStream) {
    std::cerr << "ERROR";
    exit(-1);
  }

  while (fileStream >> tam >> letters) {
    std::sort(letters.begin(), letters.end());
    char previous = letters[0];
    static std::string uniqueLetters;
    uniqueLetters.push_back(previous);

    for (char c : letters) {
      if (c != previous) {
        uniqueLetters.push_back(c);
        previous = c;
      }
    }

    std::vector<std::string> candidates = getWords(uniqueLetters, tam);
    std::vector<std::string> wordSquare = findWordSquare(candidates, tam);

    for (std::string s : wordSquare) {
      std::cout << s << std::endl;
    }

    std::cout << std::endl;
  }

  return 0;
}
Beispiel #5
0
int main (void) {
	int row, col, i, max;
	char *str = malloc(sizeof(char) * (MAX_WORD_LENGTH + 1));
	char temp[2];
	Dictionary *dict = malloc(sizeof(Dictionary));
	WordSearchPuzzle *puzzle = malloc(sizeof(WordSearchPuzzle));
	
	readDictionary(dict);
	
	readPuzzle(puzzle);
	
	//set bigger dimension of puzzle, use for determining
	//length of diagonal for() loops
	if (puzzle->height > puzzle->width) {
		max = puzzle->height;
	} else {
		max = puzzle->width;
	}
	
	temp[1] = '\0';
	
	for (row = 0; row < puzzle->height; row++) {
		for (col = 0; col < puzzle->width; col++) {
			
			//clear array, except for char at index 0
			for (i = 1; i < MAX_WORD_LENGTH + 1; i++) {
				str[i] = '\0';
			}
			
			//single char strings
			*str = puzzle->grid[row][col];
			checkString(dict, str);
			
			//build strings horizontally-right
			for (i = 1; i < puzzle->width; i++) {
				//make sure not to go too far!
				if (col + i < puzzle->width) {
					temp[0] = puzzle->grid[row][col + i];
					str = strcat(str, temp);
					checkString(dict, str);
				}
			}
			
			//clear array, except for char at index 0
			for (i = 1; i < MAX_WORD_LENGTH + 1; i++) {
				str[i] = '\0';
			}
			
			//build strings horizontally-left
			for (i = 1; i < puzzle->width; i++) {
				//make sure not to go too far!
				if (col - i > 0) {
					temp[0] = puzzle->grid[row][col - i];
					str = strcat(str, temp);
					checkString(dict, str);
				}
			}
			
			//clear array, except for char at index 0
			for (i = 1; i < MAX_WORD_LENGTH + 1; i++) {
				str[i] = '\0';
			}
			
			//build strings vertically-down
			for (i = 1; i < puzzle->height; i++) {
				if (row + i < puzzle->height) {
					temp[0] = puzzle->grid[row + i][col];
					str = strcat(str, temp);
					checkString(dict, str);
				}
			}
			
			//clear array, except for char at index 0
			for (i = 1; i < MAX_WORD_LENGTH + 1; i++) {
				str[i] = '\0';
			}
			
			//build strings vertically-up
			for (i = 1; i < puzzle->height; i++) {
				//why is this >=? top row of puzzle (height/width ints) hindering correct reading?
				if (row - i >= 0) {
					temp[0] = puzzle->grid[row - i][col];
					str = strcat(str, temp);
					checkString(dict, str);
				}
			}
			
			//clear array, except for char at index 0
			for (i = 1; i < MAX_WORD_LENGTH + 1; i++) {
				str[i] = '\0';
			}
			
			//build string diagonally up-left
			for (i = 1; i <= max; i++) {
				if (row - i >= 0 && col - i >= 0) {
					temp[0] = puzzle->grid[row - i][col - i];
					str = strcat(str, temp);
					checkString(dict, str);
				}
			}
			
			//clear array, except for char at index 0
			for (i = 1; i < MAX_WORD_LENGTH + 1; i++) {
				str[i] = '\0';
			}
			
			//build string diagonally up-right
			for (i = 1; i < max; i++) {
				if (row - i >= 0 && col + i < puzzle->width) {
					temp[0] = puzzle->grid[row - i][col + i];
					str = strcat(str, temp);
					checkString(dict, str);
				}
			}
			
			//clear array, except for char at index 0
			for (i = 1; i < MAX_WORD_LENGTH + 1; i++) {
				str[i] = '\0';
			}
			
			//build string diagonally down-left
			for (i = 1; i < max; i++) {
				if (row + i < puzzle->height && col - i >= 0) {
					temp[0] = puzzle->grid[row + i][col - i];
					str = strcat(str, temp);
					checkString(dict, str);
				}
			}
			
			//clear array, except for char at index 0
			for (i = 1; i < MAX_WORD_LENGTH + 1; i++) {
				str[i] = '\0';
			}
			//build string diagonally down-right
			for (i = 1; i < max; i++) {
				if (row + i < puzzle->height && col + i < puzzle->width) {
					temp[0] = puzzle->grid[row + i][col + i];
					str = strcat(str, temp);
					checkString(dict, str);
				}
			}
		}//end [col] for loop
	}//end [row] for loop
	
	for (i = 0; i < dict->size; i++) {
		if (dict->counts[i] > 0) {
			printf("%s (%d)\n", dict->words[i], dict->counts[i]);
		}
	}
	
	destroyDictionary(dict);
	destroyPuzzle(puzzle);
	
	free(str);
	str = NULL;
	
	return 0;
}
Beispiel #6
0
bool
ClParserParser::
parse()
{
  ClParserOperatorType op = CL_PARSER_OP_NONE;

  error_code_ = 0;

  bool expression = false;

  parse_.skipSpace();

  while (! parse_.eof()) {
    /* <expression> := <inline_operator> <expression>
       <expression> := <expression> <inline_operator> */

    if      (parse_.isString("++") || parse_.isString("--")) {
      if (parse_.isChar('+'))
        ClParserStackMgrInst->push(CL_PARSER_OP_INCREMENT);
      else
        ClParserStackMgrInst->push(CL_PARSER_OP_DECREMENT);

      ClParserStackMgrInst->toNext();

      parse_.skipChars(2);

      if (! expression) {
        ClParserParser parser(this);

        if (! parser.parse()) {
          error_code_ = parser.getErrorCode();
          goto fail;
        }

        if (parser.isAssign()) {
          error_code_ = int(ClErr::INVALID_LVALUE_FOR_ASSIGNMENT);
          goto fail;
        }
      }

      expression = true;
    }

    /* <expression> := <unary_operator> <expression> */

    else if (! expression && parse_.isOneOf(parser_unary_operator_chars)) {
      if (! readUnaryOperator(&op)) {
        error_code_ = int(ClErr::INVALID_CHARACTER);
        goto fail;
      }

      ClParserStackMgrInst->push(op);

      ClParserStackMgrInst->toNext();

      ClParserParser parser(this);

      if (! parser.parse()) {
        error_code_ = parser.getErrorCode();
        goto fail;
      }

      if (parser.isAssign()) {
        error_code_ = int(ClErr::INVALID_LVALUE_FOR_ASSIGNMENT);
        goto fail;
      }

      expression = true;
    }

    /* <expression> := '(' <expression> ')' */

    else if (! expression && parse_.isChar('(')) {
      ClParserStackMgrInst->push(CL_PARSER_OP_OPEN_R_BRACKET);

      ClParserStackMgrInst->toNext();

      parse_.skipChar();

      ClParserParser parser(this);

      /* TODO: set end char */
      if (! parser.parse() &&
          parser.getErrorCode() != int(ClErr::INVALID_CHARACTER)) {
        error_code_ = parser.getErrorCode();
        goto fail;
      }

      parse_.skipSpace();

      if (! parse_.isChar(')')) {
        error_code_ = int(ClErr::MISSING_CLOSE_ROUND_BRACKET);
        goto fail;
      }

      ClParserStackMgrInst->push(CL_PARSER_OP_CLOSE_R_BRACKET);

      ClParserStackMgrInst->toNext();

      parse_.skipChar();

      expression = true;
    }

    /* <expression> := <numeric_value> */

    else if (! expression && (parse_.isDigit() || parse_.isChar('.'))) {
      ClParserValuePtr value;

      if (! readNumericValue(value))
        goto fail;

      ClParserStackMgrInst->push(value);

      ClParserStackMgrInst->toNext();

      expression = true;
    }

    /* <expression> := <string_value> */

    else if (! expression && parse_.isOneOf(parser_string_chars)) {
      ClParserValuePtr value;

      if (! readStringValue(value))
        goto fail;

      ClParserStackMgrInst->push(value);

      ClParserStackMgrInst->toNext();

      expression = true;
    }

    /* <expression> := <array_value> */

    else if (! expression && parse_.isChar('[')) {
      ClParserStackMgrInst->push(CL_PARSER_OP_OPEN_S_BRACKET);

      ClParserStackMgrInst->toNext();

      parse_.skipChar();

      if (! readArray())
        goto fail;

      expression = true;
    }

    /* <expression> := <dict_value> */

    else if (! expression && parse_.isString("{{")) {
      ClParserStackMgrInst->push(CL_PARSER_OP_OPEN_DICT);

      ClParserStackMgrInst->toNext();

      parse_.skipChars(2);

      if (! readDictionary())
        goto fail;

      expression = true;
    }

    /* <expression> := <list_value> */

    else if (! expression && parse_.isChar('{')) {
      ClParserStackMgrInst->push(CL_PARSER_OP_OPEN_BRACE);

      ClParserStackMgrInst->toNext();

      parse_.skipChar();

      if (! readList())
        goto fail;

      expression = true;
    }

    /* <expression> := <expression> <binary_operator> <expression> */

    else if (expression && parse_.isOneOf(parser_binary_operator_chars)) {
      if (! readBinaryOperator(&op))
        goto fail;

      ClParserStackMgrInst->push(op);

      ClParserStackMgrInst->toNext();

      ClParserParser parser(this);

      if (! parser.parse()) {
        error_code_ = parser.getErrorCode();
        goto fail;
      }

      ClParserOperatorPtr op1 = ClParserOperatorMgrInst->getOperator(op);

      if (! op1->isAssignment() && parser.isAssign()) {
        error_code_ = int(ClErr::INVALID_LVALUE_FOR_ASSIGNMENT);
        goto fail;
      }

      if (op1->isAssignment())
        assign_ = true;

      expression = true;
    }

    /* <expression> := <expression> '?' <expression> ':' <expression> */

    else if (expression && parse_.isChar('?')) {
      ClParserStackMgrInst->push(CL_PARSER_OP_QUESTION_MARK);

      ClParserStackMgrInst->toNext();

      parse_.skipChar();

      ClParserParser parser1(this);

      if (! parser1.parse() &&
          parser1.getErrorCode() != int(ClErr::INVALID_CHARACTER)) {
        error_code_ = parser1.getErrorCode();
        goto fail;
      }

      parse_.skipSpace();

      if (! parse_.isChar(':')) {
        error_code_ = int(ClErr::MISSING_COLON_OPERATOR);
        goto fail;
      }

      ClParserStackMgrInst->push(CL_PARSER_OP_COLON);

      ClParserStackMgrInst->toNext();

      parse_.skipChar();

      ClParserParser parser2(this);

      if (! parser2.parse() &&
          parser2.getErrorCode() != int(ClErr::INVALID_CHARACTER)) {
        error_code_ = parser2.getErrorCode();
        goto fail;
      }

      assign_ = parser1.isAssign() | parser2.isAssign();

      expression = true;
    }

    /* <expression> := <expression> '[' <expression> ',' .... ']' */

    else if (expression && parse_.isChar('[')) {
      ClParserStackMgrInst->push(CL_PARSER_OP_OPEN_S_BRACKET);

      ClParserStackMgrInst->toNext();

      parse_.skipChar();

      if (! readArray())
        goto fail;

      expression = true;
    }

    /* <expression> := <expression> ',' <expression> */

    else if (expression && parse_.isChar(',')) {
      ClParserStackMgrInst->push(CL_PARSER_OP_COMMA);

      ClParserStackMgrInst->toNext();

      parse_.skipChar();

      ClParserParser parser(this);

      if (! parser.parse()) {
        error_code_ = parser.getErrorCode();
        goto fail;
      }

      expression = true;
    }

    /* <expression> := <variable>                               */
    /* <expression> := <variable> '.' <variable> '.' <...>      */
    /* <expression> := <variable> '[' <expression> ',' .... ']' */
    /* <expression> := <function> '(' <expression> ',' .... ')' */
    /* <expression> := <type>     '(' <expression> ',' .... ')' */

    else if (! expression &&
             ((! ClParserInst->getDollarPrefix() && parse_.isIdentifier()) ||
              (  ClParserInst->getDollarPrefix() &&
               parse_.isChar('$') && parse_.isIdentifier(1)))) {
      if (ClParserInst->getDollarPrefix() && parse_.isChar('$'))
        parse_.skipChar();

      ClParserIdentifierPtr identifier;

      if (! readIdentifier(identifier))
        goto fail;

      const std::string &name  = identifier->getName();
      ClParserScopePtr   scope = identifier->getScope();

      parse_.skipSpace();

      if (parse_.isChar('(')) {
        ClParserInternFnPtr internfn;

        if (scope.isValid())
          internfn = scope->getInternFn(name);
        else
          internfn = ClParserInst->getInternFn(name);

        if (internfn.isValid()) {
          ClParserStackMgrInst->push(internfn);

          ClParserStackMgrInst->toNext();
        }
        else {
          ClParserUserFnPtr userfn;

          if (scope.isValid())
            userfn = scope->getUserFn(name);
          else
            userfn = ClParserInst->getUserFn(name);

          if (userfn.isValid()) {
            ClParserStackMgrInst->push(userfn);

            ClParserStackMgrInst->toNext();
          }
          else {
            ClParserTypePtr type = ClParserInst->getType(name);

            if (type.isValid()) {
              ClParserStackMgrInst->push(type);

              ClParserStackMgrInst->toNext();
            }
            else {
              identifier->setFunction();

              ClParserStackMgrInst->push(identifier);

              ClParserStackMgrInst->toNext();
            }
          }
        }

        ClParserStackMgrInst->push(CL_PARSER_OP_OPEN_R_BRACKET);

        ClParserStackMgrInst->toNext();

        parse_.skipChar();

        if (! readArgList())
          goto fail;

        expression = true;
      }
      else {
        identifier->setVariable();

        ClParserStackMgrInst->push(identifier);

        ClParserStackMgrInst->toNext();

        if (parse_.isChar('[')) {
          ClParserStackMgrInst->push(CL_PARSER_OP_OPEN_S_BRACKET);

          ClParserStackMgrInst->toNext();

          parse_.skipChar();

          if (! readArray())
            goto fail;

          parse_.skipSpace();
        }

        while (parse_.isChar('.')) {
          identifier->setStructPart();

          ClParserStackMgrInst->push(CL_PARSER_OP_DOT);

          ClParserStackMgrInst->toNext();

          parse_.skipChar();

          parse_.skipSpace();

          if (! readIdentifier(identifier)) {
            error_code_ = int(ClErr::INVALID_CHARACTER);
            goto fail;
          }

          identifier->setVariable();

          ClParserStackMgrInst->push(identifier);

          ClParserStackMgrInst->toNext();

          if (parse_.isChar('[')) {
            ClParserStackMgrInst->push(CL_PARSER_OP_OPEN_S_BRACKET);

            ClParserStackMgrInst->toNext();

            parse_.skipChar();

            if (! readArray())
              goto fail;

            parse_.skipSpace();
          }
        }

        expression = true;
      }
    }
    /* <expression> := <string_value> */

    else if (! expression && ClParserInst->getDollarPrefix()) {
      std::string str;

      parse_.readNonSpace(str);

      ClParserValuePtr value = ClParserValueMgrInst->createValue(str);

      ClParserStackMgrInst->push(value);

      ClParserStackMgrInst->toNext();

      parse_.skipSpace();

      expression = true;
    }
    else {
      error_code_ = int(ClErr::INVALID_CHARACTER);
      goto fail;
    }

    parse_.skipSpace();
  }

  if (error_code_ == 0 && ! expression) {
    error_code_ = int(ClErr::NULL_EXPRESSION);
    goto fail;
  }

  if (parent_)
    parent_->parse_.setPos(parent_->parse_.getPos() + parse_.getPos());

  return true;

 fail:
  if (parent_)
    parent_->parse_.setPos(parent_->parse_.getPos() + parse_.getPos());

  return false;
}
Beispiel #7
0
int main(int argc, char* argv[])
{
	std::ifstream wordFile, inFile;
	std::queue<std::string> matchingCase;
	std::vector<std::string> dictionary, input;
	// cmake build version(as specified in cmake header
	std::cout << "VERSION " << MAJOR << "." << MINOR << std::endl;
	// if the user enters no args
	if(argc == 1) {
		std::cout << "Usage: ./auto <wordList> <inputFile>" << std::endl;
		return 1;
	// testing for retarded user
	} else if(argc == 2) {
		std::cout << "Error, must provide inputFile" << std::endl;
		return 1;
	}	
	// open dictionary text file
	if(!openGood(wordFile, argv[1])) {
		std::cout << "Error, dictionary file could not be opened\n";
		return 1;
	}
	// now open input file with the words we need to complete
	if(!openGood(inFile, argv[2])) {
		std::cout << "Error, input file could not be opened\n";
		return 1;
	}

#ifdef USE_INPUT	
	readDictionary(wordFile, dictionary, argv[1]);
	readInput(inFile, input, argv[2]);
#else
	//--------------------------------------------------------------------
	input.push_back("par");
	dictionary.push_back("apple");
	dictionary.push_back("and");
	dictionary.push_back("batman");
	dictionary.push_back("gone");
	dictionary.push_back("imaginary");
	dictionary.push_back("parachute");
	dictionary.push_back("paraglide");
	dictionary.push_back("testing");
	dictionary.push_back("zoo");
	//--------------------------------------------------------------------
#endif	

	//check to make sure list is sorted!
	//--check, ok done

	if(!search(dictionary, input, matchingCase)) {
		std::cout << "no words have been found matching...." << std::endl;
		return 1;
	}

	// print contents of queue	
	while(!matchingCase.empty()) {
		//make sure to display our queue in the order we found them
		std::cout << matchingCase.front() << std::endl;
		//pop off the front of the queue
		matchingCase.pop();
	}

	return 0;
}