C++用Insert如果原来有值并不会覆盖,记得清空
或者直接用Map[key]=value来弄
#include<bits/stdc++.h>
using namespace std;
int main(){
map<int,int>M;
M[2]=3;
M.insert({3,4});
for(auto &x:M){
cout<<x.first<<" "
<<x.second<<endl;
}
M.insert({2,5});
M.insert({3,4});
M.insert({3,4});
M.insert({3,6});
for(auto &x:M){
cout<<x.first<<" "
<<x.second<<endl;
}
M[3]=8;
for(auto &x:M){
cout<<x.first<<" "
<<x.second<<endl;
}
}
输出