打省赛的时候居然被卡语法了,啊这……虽然不被卡语法还是会T掉,但还是想写篇博客记录一下。
map在循环删除时应该这样操作:
#include <iostream>
#include <map>
using namespace std;
map <int, int> mp;
int main()
{
mp[0] = 0;
mp[1] = 1;
mp[2] = 1;
mp[3] = 1;
map <int, int>::iterator it;
for(it = mp.begin(); it != mp.end();)
{
if(it->second == 0) mp.erase(it++);
else it++;
}
for(auto it:mp) cout << it.first << " " << it.second << endl;
return 0;
}