Exemple #1
0
void test_spec3(Map *maps, int map_n) {
	for (int i = 0; i < map_n; i++)
		init(&maps[i]);
	int cmds, mid, cmd, key;
	char val[128];
	int keylist[1024];
	scanf("%d", &cmds);
	for (int i = 0; i < cmds; i++) {
		scanf("%d", &cmd);
		if (cmd == 1) {
			scanf("%d", &mid);
			print(&maps[mid]);
		} else if (cmd == 2) {	
			scanf("%d %d %s", &mid, &key, val);
			int f = map(&maps[mid], key, val);
			printf("mf %d\n", f);
		} else if (cmd == 3) {
			scanf("%d %d", &mid, &key);
			int f = unmap(&maps[mid], key);
			printf("uf %d\n", f);
		} else if (cmd == 4) {
			scanf("%d %s", &mid, val);
			int keylist_n = reverseMap(&maps[mid], val, keylist);
			printf("list");
			for (int i = 0; i < keylist_n; i++)
				printf(" %d", keylist[i]);
			puts("");
		} else {
			assert(false);
		}
	}
}
Exemple #2
0
void FrequencyMap::dump( std::ostream& os, int itemNum ) const
{
  FrequencyMap::ReFrequencyMap reFrequencyMap;
  reverseMap(reFrequencyMap);

  int totalItemNum = total();

  FrequencyMap::ReFrequencyMap::reverse_iterator rit;
  for ( rit=reFrequencyMap.rbegin(); rit!=reFrequencyMap.rend(); ++rit )
  {
    os << rit->first << "\t" << rit->second << "\n";

    --itemNum;
    if (itemNum==0)
      break;
  }
  os.flush();
}
Exemple #3
0
void FrequencyMap::highPassFilter( WordList& allowedWords, double ratio ) const
{
  allowedWords.clear();

  FrequencyMap::ReFrequencyMap reFrequencyMap;
  reverseMap(reFrequencyMap);

  FrequencyMap::ReFrequencyMap::reverse_iterator rit;

  int totalItemNum = total();

  int localItemNum(0);
  for ( rit=reFrequencyMap.rbegin(); rit!=reFrequencyMap.rend(); ++rit )
  {
    localItemNum += rit->first;
    if ( ((double)localItemNum)/totalItemNum > ratio )
      break;

    allowedWords.push_back(rit->second);
  }
}
Exemple #4
0
void test_spec4(Map *maps, int map_n) {
	for (int i = 0; i < map_n; i++)
		init(&maps[i]);
	int cmds, mid, cmd, key;
	char val[128];
	int keylist[1024];
	scanf("%d", &cmds);
	for (int i = 0; i < cmds; i++) {
		scanf("%d", &cmd);
		if (cmd == 1) {
			assert(false);
			scanf("%d", &mid);
			print(&maps[mid]);
		} else if (cmd == 2) {	
			scanf("%d %d %s", &mid, &key, val);
			int f = map(&maps[mid], key, val);
			printf("mf %d\n", f);
		} else if (cmd == 3) {
			scanf("%d %d", &mid, &key);
			int f = unmap(&maps[mid], key);
			printf("uf %d\n", f);
		} else if (cmd == 4) {
			assert(false);
			scanf("%d %s", &mid, val);
			int keylist_n = reverseMap(&maps[mid], val, keylist);
			assert(keylist_n <= 1024);
			for (int i = 0; i < keylist_n; i++)
				printf("%d%c", keylist[i], " \n"[i == keylist_n-1]);
		} else if (cmd == 5) {
			scanf("%d", &mid);
			int ret = numPairs(&maps[mid]);
			assert(ret <= 1024);
			printf("size %d\n", ret);
		} else {
			assert(false);
		}
	}
}
Exemple #5
0
int partTwo(Reps& replacements, std::string& molecule)
{
	return createMolecule(reverseMap(replacements), molecule);
}