void getG() { clearG(); gKids.resize(goodmanIndex); tKids.resize(goodmanIndex); for(Umap::iterator iter = umap.begin();iter != umap.end();++iter) { unsigned int to = iter->first; vector<unsigned int> kv; kv.push_back(to); set<unsigned int> froms = iter->second; for(set<unsigned int>::iterator jter = froms.begin();jter != froms.end();++jter) { unsigned int from = *jter; gKids[from] = kv; } } for(Bmap::iterator iter = bmap.begin();iter != bmap.end();++iter) { pair<unsigned int,unsigned int> to = iter->first; vector<unsigned int> kv; kv.push_back(to.first); kv.push_back(to.second); set<unsigned int> froms = iter->second; for(set<unsigned int>::iterator jter = froms.begin();jter != froms.end();++jter) { unsigned int from = *jter; gKids[from] = kv; } } for(S2Setmap::iterator iter = preterms.begin();iter != preterms.end();++iter) { string t = iter->first; set<unsigned int> froms = iter->second; for(set<unsigned int>::iterator jter = froms.begin();jter != froms.end();++jter) { unsigned int from = *jter; tKids[from] = t; } } }
void dump() { printf("SYMBOLS\n"); for(unsigned int i=0;i<goodmanIndex;++i) { if(i < nSym) { printf("%u\t: %s\n",i,syms[i].c_str()); } else if(i < nSym*2) { printf("%u\t: %s*\n",i,syms[i-nSym].c_str()); } else if(i == nSym*2) { printf("%u\t: %s\n",i,syms[nSym*2].c_str()); } else { unsigned int bSym = baseSym[i]; printf("%u\t: %s\n",i,syms[bSym].c_str()); } } printf("PRETERMS\n"); for(S2Setmap::iterator iter = preterms.begin();iter != preterms.end();++iter) { set<unsigned int> s = iter->second; for(set<unsigned int>::iterator jter = s.begin();jter != s.end();++jter) { unsigned int i = *jter; string sym = syms[baseSym[i]]; printf("%u -> %s\t\t\t%s -> %s\n",i,iter->first.c_str(),sym.c_str(),iter->first.c_str()); } } printf("UNARIES\n"); for(Umap::iterator iter = umap.begin();iter != umap.end();++iter) { set<unsigned int> s = iter->second; for(set<unsigned int>::iterator jter = s.begin();jter != s.end();++jter) { unsigned int i = *jter; string sym = syms[baseSym[i]]; unsigned int j = iter->first; string jsym = syms[baseSym[j]]; printf("%u -> %u\t\t\t%s -> %s\n",i,j,sym.c_str(),jsym.c_str()); } } printf("BINARIES\n"); for(Bmap::iterator iter = bmap.begin();iter != bmap.end();++iter) { set<unsigned int> s = iter->second; for(set<unsigned int>::iterator jter = s.begin();jter != s.end();++jter) { unsigned int i = *jter; string sym = syms[baseSym[i]]; unsigned int j = iter->first.first; string jsym = syms[baseSym[j]]; unsigned int k = iter->first.second; string ksym = syms[baseSym[k]]; printf("%u -> %u %u\t\t\t%s -> %s %s\n",i,j,k,sym.c_str(),jsym.c_str(),ksym.c_str()); } } }
vector<string> anagrams(vector<string>& strs) { typedef unordered_map<string, int> Umap; vector<string> res; Umap dict; for(int i = 0; i < strs.size(); i++){ string s = strs[i]; sort(s.begin(), s.end()); Umap::iterator it = dict.find(s); if(it == dict.end()){ dict.insert(Umap::value_type(s, i)); } else { if(it->second != -1){ res.push_back(strs[it->second]); it->second = -1; } res.push_back(strs[i]); } } return res; }