Advertisement
Kagalive

!COLLECTIONS-V-MASTER

Sep 30th, 2020
891
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.43 KB | None | 0 0
  1. #include <iostream>
  2. using std::cout;
  3. using std::cin;
  4.  
  5. #include <string>
  6. using std::string;
  7.  
  8. #include <vector>
  9. using std::vector;
  10. using std::begin;
  11. using std::end;
  12.  
  13. #include <algorithm>
  14. using std::sort;
  15. using std::count;
  16.  
  17. int main()
  18. {
  19.         vector<int> nums;
  20.  
  21.         for (int i = 0; i < 10; i++)
  22.         {
  23.             nums.push_back(i);
  24.         }
  25.  
  26.         for (auto item : nums)
  27.         {
  28.             cout << item << " ";
  29.         }
  30.         cout << '\n';
  31.  
  32.         vector<string> words;
  33.  
  34.         cout << "enter three words ";
  35.         for (int i = 0; i < 3; i++)
  36.         {
  37.             string s;
  38.             cin >> s;
  39.             words.push_back(s);
  40.         }
  41.  
  42.         for (auto item : words)
  43.         {
  44.             cout << item << " ";
  45.         }
  46.         cout << '\n';
  47.  
  48.         cout << "int vector nums has " << nums.size() << " elements." << '\n';
  49.  
  50.         nums[5] = 3;
  51.         nums[6] = -1;
  52.         nums[1] = 99;
  53.  
  54.         for (auto item : nums)
  55.         {
  56.             cout << item << " ";
  57.         }
  58.         cout << '\n';
  59.  
  60.         for (unsigned int i = 0; i < nums.size(); i++)
  61.         {
  62.             cout << nums[i] << " ";
  63.         }
  64.         cout << '\n';
  65.  
  66.         for (auto i = begin(nums); i != end(nums); i++)
  67.         {
  68.             cout << *i << " ";
  69.         }
  70.         cout << '\n';
  71.  
  72.         sort(begin(words), end(words));
  73.         for (auto item : words)
  74.         {
  75.             cout << item << " ";
  76.         }
  77.         cout << '\n';
  78.  
  79.         int threes = count(begin(nums), end(nums), 3);
  80.         cout << "vector of ints has " << threes << " elements with value 3" << '\n';
  81.  
  82.         int tees = count(begin(words[0]), end(words[0]), 't');
  83.         cout << "first word has " << tees << " letter t's" << '\n';
  84.  
  85.         return 0;
  86.  
  87. }
  88.  
  89.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement