예제 #1
0
	bool build(Dict &_front, Dict &_back, Dict &dict, Tree &tree, bool flag)
	{
		if (_front.empty()) return false;
		if (_front.size() > _back.size())
			return build(_back, _front, dict, tree, !flag);
		for (auto &word : _front) dict.erase(word);
		for (auto &word : _back) dict.erase(word);
		Dict hoge;
		bool piyo = false;
		for (auto &i : _front)
		{
			string word = i;
			for (auto &c : word)
			{
				char fuga = c;
				for (c = 'a'; c <= 'z'; c++)
				{
					if (c == fuga) continue;
					if (_back.count(word))
					{
						piyo = true;
						!flag ? tree[i].push_back(word): tree[word].push_back(i);
					}
					else if (!piyo && dict.count(word))
					{
						hoge.insert(word);
						!flag ? tree[i].push_back(word): tree[word].push_back(i);
					}
				}
				c = fuga;
			}
		}
		return piyo || build(hoge, _back, dict, tree, flag);
	}
TransactionType
transaction_type_from_verb(wxString const& p_phrase)
{
    typedef map<wxString, TransactionType> Dict;
    static Dict dict;
    static bool calculated_already = false;
    if (!calculated_already)
    {
        JEWEL_ASSERT (dict.empty());
        dict[expenditure_verb()] = TransactionType::expenditure;
        dict[revenue_verb()] = TransactionType::revenue;
        dict[balance_sheet_verb()] = TransactionType::balance_sheet;
        dict[envelope_verb()] = TransactionType::envelope;
        dict[generic_verb()] = TransactionType::generic;
        calculated_already = true;
    }
    JEWEL_ASSERT (!dict.empty());
    JEWEL_ASSERT
    (   dict.size() ==
        static_cast<Dict::size_type>(TransactionType::num_transaction_types)
    );
    Dict::const_iterator const it = dict.find(p_phrase);
    if (it == dict.end())
    {
        JEWEL_THROW
        (   InvalidTransactionTypeException,
            "wxString passed to transaction_type_from_verb does not "
            "correspond to any TransactionType."
        );
    }
    JEWEL_ASSERT (it != dict.end());
    return it->second;
}
예제 #3
0
int main()
{
	Dict d;
	d["pixel"] = "picture element";
	d["set"] = "math element";
	d["person"] = "animal element";
	d["football"] = "sport element";
	d["apple"] = "fruit element";
	d["water"] = "drink element";
	d["haha"] = "happy element";
	d["hehe"] = "wunai element";
	d["kao"] = "angry element";
	d["ca"] = "ca element";
	d["diu"] = "zang element";
	cout<<d["pixel"]<<endl;
	cout<<d["SET"]<<endl;
	cout<<d["FootBall"]<<endl;
	cout<<d["java"]<<endl;
	cout<<d.size()<<endl;
	cout<<d;
	d.remove("pixel");
	d.remove("Person");
	d.remove("xxxx");
	d["java"] = "computer element";
	cout<<d["pixel"]<<endl;
	cout<<d["java"]<<endl;
	cout<<d["Person"]<<endl;
	d.remove("CA");
	d.remove("kao");
	d["ai"] = "ai element";
	cout<<d["kao"]<<endl;
	cout<<d["ai"]<<endl;
	cout<<d.size()<<endl;
	cout<<d;

	return 0;
}
예제 #4
0
파일: main.cpp 프로젝트: luosch/13-cpp-hw
int main() {
    string a, b, c;
    cin >> a >> b;
    Dict d;
    d["pixel"] = a;
    d["set"] = b;
    cout << d["pixel"] << endl;
    cout << d["SET"] << endl;
    cout << d["java"] << endl;
    d.remove("pixel");
    d["java"] = "computer element";
    cout << d["pixel"] << endl;
    cout << d.size() << endl;
    cout << d;
}
예제 #5
0
void Menu_demo_central::populate_dict(Dict *d) {
	if(!d)
		return;
	const char *temp;
	temp = d->find("name");
	if(temp)
		strcpy(s_name, temp);
	temp = d->find("quadra_version");
	if(temp)
		strcpy(s_version, temp);
	temp = d->find("duration");
	if(temp) {
		int dur = atoi(temp);
		int min=dur/6000;
		int sec=(dur%6000)/100;
		if(min)
			sprintf(s_duration, ST_BOBMINUTES, min);
		else
			s_duration[0]=0;
		if(sec) {
			char st[100];
			sprintf(st, ST_BOBSECONDS, sec);
			if(min)
				strcat(s_duration, " ");
			strcat(s_duration, st);
		}
	}
	temp = d->find("time");
	if(temp) {
		int dur = atoi(temp);
		temp = Clock::time2char(dur);
		if(temp)
			strcpy(s_date, temp);
	}
	int cx[5], cw[5];
	cx[0] = 210;
	cw[0] = 120;
	cx[1] = cx[0] + cw[0] + 5;
	cw[1] = 60;
	cx[2] = cx[1] + cw[1] + 5;
	cw[2] = 60;
	cx[3] = cx[2] + cw[2] + 5;
	cw[3] = 90;
	cx[4] = cx[3] + cw[3] + 5;
	cw[4] = 80;
	int y=220, ys=21, i, j;
	zone.push_back(new Zone_text(fteam[7], inter, ST_PLAYERS, cx[0], y));
	if(!play->single()) {
		zone.push_back(new Zone_text(fteam[7], inter, ST_RESULTFRAG, cx[1], y));
		zone.push_back(new Zone_text(fteam[7], inter, ST_RESULTDEATH, cx[2], y));
	}
	zone.push_back(new Zone_text(fteam[7], inter, ST_SCORE, cx[3], y));
	zone.push_back(new Zone_text(fteam[7], inter, ST_LINES, cx[4], y)); y+=ys;
	while (!pinfos.empty()) {
		delete pinfos.back();
		pinfos.pop_back();
	}
	Dict *players = d->find_sub("players");
	if(players && players->size()<=MAXPLAYERS) {
		for(i = 0; i < (int)players->size(); i++) {
			const Dict *d2 = players->get_sub(i);
			Player_infos *pi=new Player_infos(i);
			pinfos.push_back(pi);
			const char *name = d2->find("name");
			if(name)
				strcpy(pi->name, name);
			temp = d2->find("team");
			if(temp)
				pi->team = atoi(temp);
		}
		//Reset score with freshly constructed Score object
		Score score2;
		score=score2;
		score.updateFromDict(players);
		uint8_t team_pos, team;
		for(team_pos=0; team_pos<MAXTEAMS; team_pos++) {
			team=score.team_order[team_pos];
			for(j=0; j<MAXPLAYERS; j++) {
				for(i=0; i<MAXPLAYERS; i++)
					if(score.order[j]==i && score.player_team[i]==team)
						break;
				if(i<pinfos.size()) {
					Player_infos *pi=pinfos[i];
					Font *f=inter->font;
					if(pi->team<=6)
						f=fteam[pi->team];
					zone.push_back(new Zone_text(f, inter, pi->name, cx[0], y));
					int *statp;
					if(!play->single()) {
						statp=score.stats[i].stats[CS::FRAG].get_address();
						zone.push_back(new Zone_text_field(inter, statp, cx[1], y, cw[1], fcourrier[pi->team], false));
						statp=score.stats[i].stats[CS::DEATH].get_address();
						zone.push_back(new Zone_text_field(inter, statp, cx[2], y, cw[2], fcourrier[pi->team], false));
					}
					statp=score.stats[i].stats[CS::SCORE].get_address();
					zone.push_back(new Zone_text_field(inter, statp, cx[3], y, cw[3], fcourrier[pi->team], false));
					statp=score.stats[i].stats[CS::LINESTOT].get_address();
					zone.push_back(new Zone_text_field(inter, statp, cx[4], y, cw[4], fcourrier[pi->team], false));
					y+=ys;
				}
			}
		}
	}
}
int main(int argc, char* argv[]) {

	if(argc != 2) {
		cout << "Uso: " << argv[0] << " palavras.txt" << endl;
		exit(-1);
	}
	//Inicializa o dicionario
	init_dict(argv[1]);	

	//Gera as palavras com até cinco letras
	Dict::iterator itset;
	tic();
	while(true) {
		int tamanho = gera_tamanho_palavra();
		char *new_word = gera_palavra(tamanho);

		itset = mydict.find(new_word);

		if(itset != mydict.end()) {
			mydict_found.insert(*itset);
			mydict.erase(*itset);
			qtd_encontradas++;
			
			imprime_prop();

			float prop = qtd_encontradas / (float) total_palavras;
			if(prop >= 1.0)
				break;
		}
		
		free(new_word);
	}

	cout << mydict_found.size() << ":" << mydict.size() << endl;

	total_palavras = mydict.size();

	controle=1;

	// Junta duas palavras para gerar palavras maiores
	Dict::iterator it[2];
	char* combined[2];
	for(it[0] = mydict_found.begin(); it[0]!=mydict_found.end(); ++it[0]) {
		for(it[1] = mydict_found.begin(); it[1]!=mydict_found.end(); ++it[1]) {
			combined[0] = mystrcat(*it[0], *it[1]);
			combined[1] = mystrcat(*it[1], *it[0]);
			
			for(int i=0; i<2; i++) {
				itset = mydict.find(combined[i]);
				if(itset != mydict.end()) {
					//cout << qtd_encontradas << " - combined: " << combined[i] << endl;
					mydict_found.insert(*itset);
					mydict.erase(*itset);
					qtd_encontradas++;

					imprime_prop();

					float prop = qtd_encontradas / (float) total_palavras;
					if(prop >= 1.0)
						break;
				}
				free(combined[i]);
			}
		}
	}
		
	fclose(arq_palavras);
	cout << "elapsed time: " << toc() << endl;

	return 0;
}