CPP   11

stl

Guest on 5th July 2022 05:01:40 PM

  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <list>
  5. #include <set>
  6. #include <map>
  7.  
  8. using namespace std;
  9.  
  10. int main() {
  11.   string s("mirko");
  12.   cin >> s;
  13.   cout << "s = " << s << endl;
  14.   cout << s.length() << endl;
  15.   cout << s.size() << endl;
  16.   s[1] = 'a';
  17.   for (unsigned i = 0; i < s.size(); i++)
  18.     cout << s[i] << endl;
  19.   cout << s + s << endl;
  20.  
  21.   string s1;
  22.   s1 = s;
  23.  
  24.   for (string::iterator i = s.begin(); i != s.end(); i++)
  25.     cout << *i << endl;
  26.  
  27.   for (string::reverse_iterator i = s.rbegin(); i != s.rend(); i++)
  28.     cout << *i << endl;
  29.  
  30.   vector<int> v(10);
  31.   cout << v.size() << endl;
  32.   cout << v.capacity() << endl;
  33.  
  34.   v.resize(13);
  35.   cout << v.size() << endl;
  36.   cout << v.capacity() << endl;
  37.   v[12] = 12;
  38.  
  39.   for (vector<int>::iterator i = v.begin(); i != v.end(); i++)
  40.     cout << *i << endl;
  41.  
  42.   for (unsigned i = 0; i < v.size(); i++)
  43.     v[i] = i * i;
  44.  
  45.   for (vector<int>::iterator i = v.begin(); i != v.end(); i++) {
  46.     *i *= 2;
  47.     cout << *i << endl;
  48.   }
  49.  
  50.   vector<vector<int> > m;
  51.   m.push_back(vector<int>(3));
  52.   m.push_back(vector<int>(3));
  53.   for (unsigned i = 0; i < m.size(); i++)
  54.     for (unsigned j = 0; j < m[i].size(); j++)
  55.       m[i][j] = i * j;
  56.  
  57.   for (vector<vector<int> >::iterator i = m.begin(); i != m.end(); i++) {
  58.     for (vector<int>::iterator j = i->begin(); j != i->end(); j++)
  59.       cout << *j << " ";
  60.     cout << endl;
  61.   }
  62.  
  63.   list<int> l;
  64.   cout << l.size() << endl;
  65.  
  66.   set<int> skup1;
  67.   cout << skup1.size() << endl;
  68.   skup1.insert(4);
  69.   skup1.insert(2);
  70.   skup1.insert(8);
  71.   skup1.insert(4);
  72.   cout << skup1.size() << endl;
  73.   if (skup1.count(2))
  74.     cout  << "Dvojka je u skupu" << endl;
  75.   else
  76.     cout << "Dvojka nije u skupu" << endl;
  77.   for (set<int>::iterator i = skup1.begin(); i != skup1.end(); i++)
  78.     cout << *i << endl;
  79.  
  80.   map<string, int> ocene;
  81.   ocene["Branko"] = 9;
  82.   ocene["Pera"] = 10;
  83.   ocene["Zika"] = 7;
  84.   ocene["Zika"] = 9;
  85.   ocene["Mirko"] = 9;
  86.   cout << ocene.size() << endl;
  87.   cout << ocene["Branko"] << endl;
  88.   map<string, int>::iterator tmp = ocene.find("Mirko");
  89.   if (tmp != ocene.end())
  90.     cout << tmp->first << "-" << tmp->second << endl;
  91.   cout << ocene.size() << endl;
  92.   for(map<string, int>::iterator i = ocene.begin(); i != ocene.end(); i++)
  93.     cout << i->first << " - " << i->second << endl;
  94.  
  95.   return 0;
  96. }

Raw Paste


Login or Register to edit or fork this paste. It's free.