Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3. #include <set>
  4. #include <vector>
  5. #include <queue>
  6. using namespace std;
  7.  
  8. struct cmp {
  9.     bool operator()(const int a, const int b) {
  10.         return a >= b;
  11.     }
  12. };
  13.  
  14. void print_ms(multiset<int> ms) {
  15.     for (multiset<int>::iterator it = ms.begin(); it != ms.end(); it++) {
  16.         cout << *it << " ";
  17.     }
  18.     cout << "*";
  19.     cout << endl;
  20. }
  21.  
  22.  
  23. int main() {
  24.     //--------1-------
  25.     //begin() - constant O(1)
  26.     //set<int>::iterator ... ++ - O(logn), где n - высотадерева (случай когда переход из левого поддерева корня в правый)
  27.  
  28.  
  29.     //--------2--------
  30.     map<int, int> mp = map<int, int>();
  31.     int keyAdd = 2;
  32.     int val = 3;
  33.     map<int, int>::iterator itKey = mp.find(keyAdd);
  34.     if (itKey == mp.end())
  35.         cout << "it is here" << endl;
  36.     else
  37.         cout << "there is no such key" << endl;
  38.     mp.insert(make_pair(keyAdd, val));
  39. //    mp.insert(itKey, val);
  40.     cout << mp[keyAdd] << endl;
  41.  
  42.  
  43.     //--------3-----------
  44.     set<int, cmp> st = set<int, cmp>();
  45.     st.insert(4);
  46.     st.insert(5);
  47.     cout << *st.begin() << endl;
  48.  
  49.  
  50.     //--------4---------
  51.     //нет, константный итератор не изменяем
  52.     //using namespace std;
  53.     vector<int> v = vector<int>();
  54.     for (int i = 0; i < 5; i++)
  55.         v.push_back(i);
  56.     for (vector<int>::iterator it = v.begin(); it != v.end(); it++)
  57.         *it += 10;
  58.     for (vector<int>::iterator it = v.begin(); it != v.end(); it++)
  59.         cout << *it << " ";
  60.     cout << endl;
  61.     cout << "it works!" << endl;
  62.  
  63.  
  64.     //---------5--------
  65. //    for (vector<int>::const_iterator it  = v.begin(), end = v.end(); it != end; it++) {
  66. //        if (*it % 2 == 0)
  67. //            v.push_back(++*it);//опять константный итератор ...
  68. //    }
  69.  
  70.  
  71.     //----------6---------
  72.     cout << "task 6" << endl;
  73.     int tmp;
  74.     queue<int> q = queue<int>();
  75.     multiset<int> ms = multiset<int>();
  76.     int n = 3;
  77.     for (int i = 0; i < n; i++) {
  78.         cin >> tmp;
  79.         if (tmp == 0)
  80.             return 0;
  81.         q.push(tmp);
  82.         ms.insert(tmp);
  83.     }
  84.  
  85.  
  86.     //0 символ конца. Разрешили читать не из файла
  87.     while (tmp != 0) {
  88.         cout << "now min is: " << *ms.begin() << "\n";
  89. //        cout << q.front() << "need to deleted" << endl;
  90.         ms.erase(ms.find(q.front()));
  91.         q.pop();
  92.         cin >> tmp;
  93.         q.push(tmp);
  94.         ms.insert(tmp);
  95. //        print_ms(ms);
  96.     }
  97.  
  98.     return 0;
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement