map迭代器

#include<iostream>
#include<map>
#include<queue>
using namespace std;
queue<int> qu;
map<int, int> mp;
int sss(int a)
{
for(auto it=mp.begin();it!=mp.end();it++)
{
a=a-(*it).second;
if(a<=0)
return (*it).first;
}
}
int main()
{
int cnt=0;
for(int i=1;i<=14;i++)
mp.insert({i,i}); //不加{}会报错
for(auto l:mp)
{
cout<<l.first<<" "<<l.second<<endl;
}
//map<int, int>::iterator it;
// for(it=mp.begin();it!=mp.end();it++);
// cout<<it->first<<" "<<it->second<<endl;
// string s,b;
// int t,d;
// cin>>t;
// while(t--)
// {
// cin>>s>>d;
// if(s[0]=='a')
// mp[d]++;
// else if(s[0]=='d')
// mp[d]--;
// else
// {
// cout<<sss(d)<<endl;
// }
// }
return 0;
}

posted @ 2022-04-21 23:13  xxj112  阅读(178)  评论(0)    收藏  举报