fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. // this adds the key value pair in map instead of updating it, dont know how to overcome this???
  4. struct f{
  5. bool operator()( int a, int b){
  6. return a<b;
  7. }
  8. };
  9. int main() {
  10. map<int,int,f> m;
  11. m[1]=2;
  12. m[2]=1;
  13. m[6]=1;
  14. m[3]=4;
  15. m[6]=34;
  16. m[3]=5;
  17. cout<<m.size()<<"\n";
  18. for(auto x: m) cout<<x.first<<" "<<x.second<<"\n";
  19. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
4
1 2
2 1
3 5
6 34