Advertisement
Imran_Mohammed

Everything_of_Map

Jan 28th, 2021 (edited)
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.26 KB | None | 0 0
  1.        // In The Name Of Allah
  2.  
  3. #include<bits/stdc++.h>
  4. using namespace std;
  5.  
  6.  
  7.  
  8. int main()
  9. {
  10.     //Map always sorted but not unique
  11.     //greater<int> for decending order ex :  map<int , int , greater<int> > strength;
  12.  
  13.     //Map Declaration :
  14.     map <string , string> gender;
  15.     gender ["imran"] = "male";
  16.     gender ["imrose"] = "female";
  17.     cout << gender["imran"] << " " << gender["imrose"] << endl;//male female
  18.  
  19.     //User Input :
  20.     map <string , int> id;
  21.     int n;
  22.     cin >> n;
  23.     for(int i=0; i<n; i++){
  24.         string s;
  25.         int d;
  26.         cin >> s >> d;
  27.         id[s] = d;
  28.     }
  29.     for(auto u : id){
  30.         cout << u.first << " " << u.second << endl;
  31.     }
  32.  
  33.     //Element count :
  34.     //Sorted (key value base)
  35.     vector< long long > v = {1, 12345678, 1234, 12345678, 11, 3445, 1};
  36.     map <long long ,int> cnt;
  37.     for(int i=0; i<v.size(); i++){
  38.         cnt [v[i]]++ ;
  39.     }
  40.     cout << cnt[12345678] << endl;//2
  41.     for(auto u: cnt){
  42.         cout << u.first <<" " << u.second << endl;
  43.     }
  44.     /* 1 2
  45.     11 1
  46.     1234 1
  47.     3445 1
  48.     12345678 2/*
  49.  
  50.  
  51.     //Unique vale :
  52.     map <int , int > c;
  53.     c[1] = 1;
  54.      c[2] = 2;
  55.       c[3] = 1;
  56.        c[3] = 2;
  57.        cout << c.size() << endl;//3
  58.     return 0;
  59. }
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement