Пример #1
0
int main(int argc, const char * argv[])
{
    if(argc != 3){
        fprintf(stderr, "invalid input\n");
        return 1;
    }
    
    FILE *dictFilePtr = fopen(argv[1], "r");
    if(dictFilePtr == NULL) {
      fprintf(stderr, "Cannot open the dictionary file\n");
      return 1;
    }
    
    FILE *dataFilePtr = fopen(argv[2], "r");
    if(dataFilePtr == NULL) {
        fprintf(stderr, "Cannot open the data file\n");
        return 1;
    }
    
    readDict(dictFilePtr);
    fclose(dictFilePtr);
    scanData(dataFilePtr);
    fclose(dataFilePtr);
    
    printTrie();
    
    return 0;
}
Пример #2
0
int main()
{
    FILE *fp = fopen("dictionary.txt", "r");
    CVector** dict = malloc(MAX_WORD_SIZE * sizeof(CVector*));
    for (int i = 0; i < MAX_WORD_SIZE; i++) {
        dict[i] = NULL;
    }
    readDict(fp, dict);
    fclose(fp);
    char replay = 1;
    while (replay == 1) {
        int wordLength = chooseWordLength(dict);
        CVector *wordVec = dict[wordLength];
        playGame(wordVec, wordLength);
        printf("Do you want to replay (Y/N)? ");
        char *s = malloc(MAX_WORD_SIZE);
        scanf("%s", s);
        if (strcmp(s, "y") == 0 || strcmp(s, "Y") == 0) replay = 1;
        else {
            replay = 0;
            free(wordVec);
        }
    }
    for (int i = 0; i < MAX_WORD_SIZE; i++) {
        cvec_dispose(dict[i]);
//        if (dict[i] != NULL) {
//            cvec_dispose(dict[i]);
//        }
    }
    free(dict);
    
    return 0;
}
Пример #3
0
Tokens::Bencode*
readBencode(std::ifstream& inp)
{
    std::cout << "readBencode" << std::endl;

    Tokens::Bencode* bencode;

    // check the next character without removing from the stream
    char ch = inp.peek();
    if (ch == 'd')
    {
        bencode = readDict(inp);
    }
    else if(ch == 'l')
    {
        assert("Not implemented LIST" == "0");
    }
    else if (ch == 'i')
    {
        assert("Not implemented INTEGER" == "0");
    }
    else if ( isDigit(ch))
    {
        bencode = readStr(inp);
    }
    else
    {
        assert(ch == 'e');
    }



    return bencode;
}
Foam::OutputFilterFunctionObject<OutputFilter>::OutputFilterFunctionObject
(
    const word& name,
    const Time& t,
    const dictionary& dict
)
:
    functionObject(name),
    time_(t),
    dict_(dict),
    regionName_(polyMesh::defaultRegion),
    dictName_(),
    enabled_(true),
    storeFilter_(true),
    timeStart_(-VGREAT),
    timeEnd_(VGREAT),
    nStepsToStartTimeChange_
    (
        dict.lookupOrDefault("nStepsToStartTimeChange", 3)
    ),
    outputControl_(t, dict, "output"),
    evaluateControl_(t, dict, "evaluate")
{
    readDict();
}
Foam::OutputFilterFunctionObject<OutputFilter>::OutputFilterFunctionObject
(
    const word& name,
    const Time& t,
    const dictionary& dict
)
:
    functionObject(name),
    time_(t),
    //    dict_(dict),
    regionName_(polyMesh::defaultRegion),
    dictName_(),
    enabled_(true),
    storeFilter_(true),
    timeStart_(-VGREAT),
    timeEnd_(VGREAT),
    nStepsToStartTimeChange_
    (
        dict.lookupOrDefault("nStepsToStartTimeChange", 3)
    ),
    outputControl_(t, dict, "output"),
    evaluateControl_(t, dict, "evaluate")
#ifdef FOAM_FUNCTIONOBJECT_HAS_SEPARATE_WRITE_METHOD_AND_NO_START
    ,lastTimeStepExecute_(-1)
#endif
{
    Dbug << this->name() << " OutputFilterFunctionObject::Constructor" << endl;

    read(dict);
    readDict();
}
Пример #6
0
BushuViewWidget::BushuViewWidget( QWidget *parent, const char *name )
        : CharDictViewBase( parent, name )
{
    setupWidgets();
    readDict();

    readConfig();
}
bool Foam::OutputFilterFunctionObject<OutputFilter>::start()
{
    readDict();

    if (enabled_&&storeFilter_)
    {
        allocateFilter();
    }

    return true;
}
bool Foam::OutputFilterFunctionObject<OutputFilter>::start()
{
    Dbug << this->name() << " OutputFilterFunctionObject::start()" << endl;

    readDict();

    if (enabled_ && storeFilter_)
    {
        allocateFilter();
    }

    Dbug << this->name() << " OutputFilterFunctionObject::start() - end" << endl;

    return true;
}
Пример #9
0
/// reads the next plist type
/// @param level the level we're currently parsing
QVariant BasePListParser::readNextPlistType( int level )
{
    if( readNextElement("",level) ) {
        // reads a dictionary
        if( xml_->name().compare( "dict", Qt::CaseInsensitive ) == 0 ) {
            return readDict();

        // reads an array
        } else if( xml_->name().compare( "array", Qt::CaseInsensitive ) == 0 ) {
            return readList( );

        // reads a string
        } else if( xml_->name().compare( "string", Qt::CaseInsensitive ) == 0 ) {
            return readElementText();
        }
    }
    return QVariant();
}
Foam::OutputFilterFunctionObject<OutputFilter>::OutputFilterFunctionObject
(
    const word& name,
    const Time& t,
    const dictionary& dict
)
:
    functionObject(name),
    time_(t),
    dict_(dict),
    regionName_(polyMesh::defaultRegion),
    dictName_(),
    enabled_(true),
    storeFilter_(true),
    outputControl_(t, dict)
{
    readDict();
}
Пример #11
0
static Obj *readObject( istream& is )
{
	if( !eat( is ) ) {
		return NULL;
	}

	int ch = is.peek();

	if( (ch == '-') || (ch >= '0' && ch <= '9') ) {
		return readScalar( is );
	} else if( ch == '"' ) {
		return readString( is );
	} else if( ch == '(' ) {
		return readTuple( is );
	} else if( ch == '{' ) {
		return readDict( is );
	} else {
		return readName( is );
	}
}
Пример #12
0
int main(int argc, char **argv) {
    wxInitializer wx_initializer;
    if ( !wx_initializer ) {
        fprintf(stderr, "Failed to initialize the wxWidgets library, aborting.");
        return -1;
    }
    wxCmdLineParser cmd_parser(cmdLineDesc, argc, argv);
    
    long run_count = 10;
    wxString grid_path, dict_path;
    
    bool is_rand    = false;
    bool is_verbose = false;
    
    switch ( cmd_parser.Parse() ) {
        case -1:
            return 0;
        case 0:
            cmd_parser.Found(wxT("count"), &run_count);
            is_rand    = cmd_parser.Found(wxT("rand"));
            is_verbose = cmd_parser.Found(wxT("verbose"));
            grid_path  = cmd_parser.GetParam(0);
            dict_path  = cmd_parser.GetParam(1);
            wxLogDebug(wxT("grid_path = ") + grid_path + wxT("\n"));
            wxLogDebug(wxT("dict_path = ") + dict_path + wxT("\n"));
            wxLogDebug(wxT("run_count = %d\n"), run_count);
            break;
        default:
            return 0;
    }
    std::vector< wxLongLong > durs(run_count); // durations
    std::vector< wxString > words_out;
    DictType dict;
    GridType grid;
    AllWordsType all_words;
    CharsTransType trans_type;
    
    readDict(dict_path, dict);
    generateAllWords(dict, all_words, trans_type);
    readGrid(grid_path, grid);
    
    if ( is_rand )
        srand(time(NULL));
    
    for (long i = 0; i < run_count; ++i) {
        if ( !is_rand )
            srand(42);
        words_out.clear();
        durs.at(i) = wxGetLocalTimeMillis();
        generateCross(grid,all_words,trans_type,words_out);
        if ( words_out.size() == 0 )
            wxPrintf(wxT("Error in creating #%-2i!\n"),i+1);
        durs.at(i) = wxGetLocalTimeMillis() - durs.at(i);
        if ( is_verbose )
            wxPrintf(wxT("Time to generate  #%-2i is ") 
                + durs.at(i).ToString() + wxT(" ms\n"), i+1);
    }
    wxLongLong tm_total = std::accumulate(durs.begin(),durs.end(), wxLongLong(0,0));
    wxLongLong tm_mean  = (tm_total + run_count/2) / run_count;
    wxPrintf(wxT("Total time = ") + tm_total.ToString() + wxT(" ms.\nMean time  = ") 
        + tm_mean.ToString() + wxT(" ms.\n"));
    return 0;
}