本文整理汇总了C++中unordered_map::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ unordered_map::begin方法的具体用法?C++ unordered_map::begin怎么用?C++ unordered_map::begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unordered_map
的用法示例。
在下文中一共展示了unordered_map::begin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: subsetsWithDup
vector<vector<int>> subsetsWithDup(unordered_map<int, int>& mapNums) {
vector<vector<int>> ret = {{}};
vector<vector<int>> tret = {};
if(mapNums.size() == 0) return ret;
int count = (mapNums.begin())->second;
int nums = (mapNums.begin())->first;
mapNums.erase(mapNums.begin());
vector<vector<int>> tmp = subsetsWithDup(mapNums);
for(int i=0; i<count; i++) {
vector<int> t(i+1, nums);
tret.push_back(t);
}
for(auto t:tmp)
if(t.size()) ret.push_back(t);
for(auto tr:tret)
ret.push_back(tr);
for(auto tr : tret) {
for(auto t : tmp) {
if(!t.size()) continue;
vector<int> tt(tr.begin(), tr.end());
tt.insert(tt.begin(), t.begin(), t.end());
ret.push_back(tt);
}
}
return ret;
}
示例2: UpdateData
//更新记录
bool SqliteManager::UpdateData(sqlite3* MyDB, string tableName, unordered_map<string, string> paraInfoSTR, unordered_map<string, INT64> paraInfoINT, string condition) {
string strPara;
//字符串类型参数的拼接
unordered_map<string, string>::iterator itor1;
for (itor1 = paraInfoSTR.begin(); itor1 != paraInfoSTR.end(); itor1++)
{
strPara += itor1->first + "='" + itor1->second + "',";
}
//整型参数的拼接
unordered_map<string, INT64>::iterator itor2;
for (itor2 = paraInfoINT.begin(); itor2 != paraInfoINT.end(); itor2++)
{
char str[50];
sprintf(str, "%d", itor2->second);
string myStr(str);
strPara += itor2->first + "=" + myStr + ",";
}
//去掉最后一个逗号
strPara.erase(strPara.size() - 1, 1);
string sqlstr = "update " + tableName + " set " + strPara + " " + condition;//sql语句
//注册超时等待时间为1000ms
sqlite3_busy_timeout(MyDB, 1000);
//执行
char* errMsg;
int result = sqlite3_exec(MyDB, sqlstr.c_str(), NULL, NULL, &errMsg);
if (result != SQLITE_OK)
return false;
return true;
}
示例3:
bool isTheSame2(unordered_map<char, int>&check, unordered_map<char, int>&record) {
for (auto it = check.begin(); it!=check.end(); it++){
if (it->second != record[it->first]) return false;
}
for (auto it = record.begin(); it!=record.end(); it++) {
if (it->second != check[it->first]) return false;
}
return true;
}
示例4: RunThread2
void RunThread2()
{
//int gameDiff = D2CLIENT_GetDifficulty();
int gameDiff = 1;
BnetData* pData = (*p_D2LAUNCH_BnData);
char* accountNameChar = pData->szAccountName;
char* charName = pData->szPlayerName; //GetCharName();
std::string accountNameCharString(accountNameChar);
std::string charNameCharString(charName);
string jsonData = "{\"data\":{\"AccountName\":\"" + accountNameCharString + "\",\"CharName\":\"" + charNameCharString + "\",";
jsonData += "\"GameDiff\":\"" + std::to_string(gameDiff) + "\",\"CompressedData\":[";
unordered_map<unsigned int, unsigned __int64>::const_iterator it;
for (it = _pickedItems.begin(); it != _pickedItems.end(); it++) {
jsonData += "{\"ItemKey\":\"" + std::to_string((*it).first) + "\", \"ItemValue\":\"" + std::to_string((*it).second) + "\"},";
}
if (_pickedItems.size() > 0) {
jsonData.pop_back(); // remove last ,
}
jsonData += "], \"Timers\":[";
unordered_map<int, int>::const_iterator it2;
for (it2 = _timers.begin(); it2 != _timers.end(); it2++) {
jsonData += "{\"LvlNo\":\"" + std::to_string((*it2).first) + "\", \"Time\":\"" + std::to_string((*it2).second) + "\"},";
}
if (_timers.size() > 0) {
jsonData.pop_back(); // remove last ,
}
jsonData += "]}}\n";
//_oldItems.clear();
//SetCharName(""); // will be reset in core loop the fuck is this
DWORD dwWrite, dwRead;
bool flg = WriteFile(hPipe, jsonData.c_str(), jsonData.size(), &dwWrite, NULL);
}
示例5: setup
routing_table* setup(char routerName)
{
routing_table* ret = new routing_table();
ifstream infile;
infile.open(portFile);
if (infile.fail())complain("cannot open " + portFile);
string line;
while (!infile.eof())
{
getline(infile, line);
if (!line.empty())
{
int p = line.find("=", 0);
if (p<0)complain("malformed " + portFile);
ports.insert(pair<char, int>(line[0], atoi(line.substr(p + 1).c_str())));
}
}
infile.close();
infile.open(linkFile);
if (infile.fail())complain("cannot open " + linkFile);
while (!infile.eof())
{
getline(infile, line);
if (!line.empty() && tolower(line[0]) == tolower(routerName))
{
vector<string> output = split(line, ",");
int o, d;
unordered_map<char, int>::iterator i;
for (i = ports.begin(); i != ports.end(); i++)
{
if (tolower(i->first) == tolower(routerName))
{
o = i->second;
break;
}
}
if (i == ports.end())complain("bad configuration files");
for (i = ports.begin(); i != ports.end(); i++)
{
if (tolower(i->first) == tolower(output[1][0]))
{
d = i->second;
break;
}
}
if (i == ports.end())complain("bad configuration files");
ret->insert(routing_entry(output[1][0], atoi(output[2].c_str()), o, d));
}
}
infile.close();
return ret;
}
示例6:
unordered_map<long,long> operator+(unordered_map<long,long> x,unordered_map<long,long>y)
{
unordered_map<long,long> result;
for(auto i=x.begin();i!=x.end();++i)
result[i->first]=x[i->first];
for(auto i=y.begin();i!=y.end();++i)
result[i->first]+=y[i->first];
return result;
}
示例7: main
int main()
{
// freopen("in.txt","r",stdin);
string name,party,club;
char ins[100],*ptr;
int TC,tmp,ans;
TC = atoi(gets(ins));
gets(ins);
while(TC--)
{
name_set.clear(); party_set.clear(); club_set.clear();
memset(graph,0,sizeof(graph));
N = 1;
while(gets(ins) && strlen(ins))
{
ptr = strtok(ins," ");
name = string(ptr);
ptr = strtok(NULL," ");
party = string(ptr);
graph[get(name_set,name)][get(party_set,party)] = 1;
while(ptr = strtok(NULL," "))
{
club = string(ptr);
graph[source()][get(club_set,club)] = 1;
graph[get(club_set,club)][get(name_set,name)] = 1;
}
}
tmp = (club_set.size() - 1) / 2;
for(unordered_map<string,int>::iterator it = party_set.begin();it != party_set.end();it++)
graph[it->second][target()] = tmp;
ans = 0;
visited.reset();
while(tmp = maxflow(source(),INT_MAX))
{
ans += tmp;
visited.reset();
}
if(ans != club_set.size()) printf("Impossible.\n");
else
for(unordered_map<string,int>::iterator it_name = name_set.begin();it_name != name_set.end();it_name++)
for(unordered_map<string,int>::iterator it_club = club_set.begin();it_club != club_set.end();it_club++)
if(graph[it_name->second][it_club->second])
{
printf("%s %s\n",(it_name->first).c_str(),(it_club->first).c_str());
break;
}
if(TC) printf("\n");
}
return 0;
}
示例8: while
~trieNode() {
auto node = children.begin();
while(node != children.end()) {
delete node->second;
node = children.erase(node);
}
}
示例9: Initialize
void VectorFactorsExtractor::Initialize(
int _numberOfLabels, int _numberOfFeatures,
int _numberOfCliques,
const unordered_map<int, unordered_set<int> >& cliquePossibleFeatures)
{
numberOfLabels = _numberOfLabels;
numberOfFeatures = _numberOfFeatures;
numberOfCliques = _numberOfCliques;
cliqueFeatureConverter.resize(numberOfCliques);
dimension = 2 * numberOfLabels + numberOfCliques;
// Iterate over cliques
int enumerator = 0;
for (auto cliqueIterator = cliquePossibleFeatures.begin();
cliqueIterator != cliquePossibleFeatures.end();
++cliqueIterator)
{
unordered_map<int, int> featureToPositionInVector;
const unordered_set<int>& possibleFeatures =
cliqueIterator->second;
// Find positions in vector for features in clique
for (auto featureIterator = possibleFeatures.begin();
featureIterator != possibleFeatures.end();
++featureIterator)
{
featureToPositionInVector[*featureIterator] =
dimension;
++dimension;
}
cliqueFeatureConverter[cliqueIterator->first] =
std::move(featureToPositionInVector);
++enumerator;
printf("\rEvaluated %d cliques", enumerator);
}
}
示例10: printGraph
void printGraph(){
queue<node*> list;
list.push(&graph.at("Quinn"));
while(!list.empty()){
node*n = list.front();
list.pop();
for(node* n2 : n->neighbours){
if(n2->visited == false){
list.push(n2);
n2->depth=(n->depth+1);
n2->visited = true;
}
}
}
vector<string> vec;
for(auto ele = graph.begin(); ele != graph.end(); ++ele){
string s = "";
if(ele->second.depth < 0)
s = ele->first + " uncool";
else
s= ele->first + " " + to_string(ele->second.depth);
vec.push_back(s);
}
sort(vec.begin(),vec.end());
for(string ele : vec)
cout << ele <<endl;
}
示例11: main
int main()
{
freopen("mirror.in","r",stdin);
freopen("mirror.out","w",stdout);
READ(N), READ(M), READ(K);
for (int i=1;i<=K;i++)
{
int x, y;
READ(x), READ(y);
INS(x-1,y-1,SE), INS(x-1,y,SW), INS(x,y,NW), INS(x,y-1,NE);
}
for (int i=1;i<M;i++) INS(0,i,NE|NW), INS(N,i,SE|SW);
for (int i=1;i<N;i++) INS(i,0,NW|SW), INS(i,M,NE|SE);
INS(0,0,SW|NW|NE), INS(0,M,NW|NE|SE);
INS(N,0,NW|SW|SE), INS(N,M,SW|SE|NE);
for (unordered_map<long long,int>::iterator i=S.begin(); i!=S.end(); i++)
{
int x=i->fi/(M+1), y=i->fi%(M+1);
A[oA(x,y)].insert(oB(x,y));
B[oB(x,y)].insert(oA(x,y));
}
int X, Y, D;
char s[3];
scanf("%d%d%s",&X,&Y,s);
D=(s[0]=='N' && s[1]=='E'? NE: s[0]=='S' && s[1]=='E'? SE: s[0]=='S' && s[1]=='W'? SW: NW);
if (D==NW? GO(X-1,Y-1,D): D==NE? GO(X-1,Y,D): D==SE? GO(X,Y,D): GO(X,Y-1,D))
{
ans++, D=L(D,2);
D==NW? GO(X-1,Y-1,D): D==NE? GO(X-1,Y,D): D==SE? GO(X,Y,D): GO(X,Y-1,D);
}
printf("%lld\n",ans);
return 0;
}
示例12: save_help_wanted
void save_help_wanted(fstream& lbfile)
{
save_primitive<int>(lbfile, ai_detail::next_job_id);
save_primitive<int>(lbfile, jobs_board.size());
for (auto it = jobs_board.begin(); it != jobs_board.end(); ++it)
{
save_primitive<int>(lbfile, it->second.type);
save_primitive<int>(lbfile, it->second.job_id);
save_primitive<uint8_t>(lbfile, it->second.current_step);
save_primitive<int>(lbfile, it->second.assigned_to);
save_primitive<int>(lbfile, it->second.steps.size());
for (auto steps = it->second.steps.begin();
steps != it->second.steps.end(); ++steps)
{
save_primitive<int>(lbfile, steps->type);
save_primitive<int16_t>(lbfile, steps->target_x);
save_primitive<int16_t>(lbfile, steps->target_y);
save_primitive<uint8_t>(lbfile, steps->target_z);
save_primitive<int>(lbfile, steps->component_id);
save_primitive<bool>(lbfile, steps->requires_skill);
save_primitive<string>(lbfile, steps->skill_name);
save_primitive<int>(lbfile, steps->placeholder_structure_id);
save_primitive<char>(lbfile, steps->required_skill_difficulty);
}
}
}
示例13: CompareTradeMapAndEmit
void CSingleUser::CompareTradeMapAndEmit(unordered_map<string, TradeField*> &oldMap, unordered_map<string, TradeField*> &newMap)
{
for (unordered_map<string, TradeField*>::iterator it = newMap.begin(); it != newMap.end(); ++it)
{
TradeField* pNewField = it->second;
unordered_map<string, TradeField*>::iterator it2 = oldMap.find(pNewField->ID);
if (it2 == oldMap.end())
{
// 没找到,是新单
m_msgQueue->Input_Copy(ResponeType::ResponeType_OnRtnTrade, m_msgQueue, m_pClass, 0, 0, pNewField, sizeof(TradeField), nullptr, 0, nullptr, 0);
}
else
{
TradeField* pOldField = it2->second;
int Qty = pNewField->Qty - pOldField->Qty;
if (Qty > 0)
{
// 有变化的单
TradeField* pField = new TradeField;
memcpy(pField, pNewField, sizeof(TradeField));
pField->Qty = Qty;
m_msgQueue->Input_Copy(ResponeType::ResponeType_OnRtnTrade, m_msgQueue, m_pClass, 0, 0, pNewField, sizeof(TradeField), nullptr, 0, nullptr, 0);
delete[] pField;
}
}
}
}
示例14:
~PartFile()
{
for (auto it = parts.begin(); it != parts.end(); ++it) {
delete it->second;
}
parts.clear();
}
示例15: printMap
void printMap(const unordered_map<string, int>& myMap)
{
for (auto iter = myMap.begin(); iter != myMap.end(); iter++) {
cout << iter->first << ": " << iter->second << endl;
}
cout << "-----" << endl;
}