Advertisement
Guest User

Code_FAST_3

a guest
Jul 19th, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.69 KB | None | 0 0
  1. // 01_03_Task3_Code_FAST_3.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream> //for std::cout
  6. #include <string>
  7. #include <sstream>
  8. #include <iomanip>  
  9. #include <vector>
  10. #include <iterator> //for std::ostream_iterator
  11. #include <algorithm> //for std::copy
  12. #include <utility>  //pair<vey, value>
  13. #include <set>
  14. #include <unordered_set>
  15.  
  16. using namespace std;
  17.  
  18. void PrintV(vector<int> v)
  19. {
  20.     std::copy(v.begin(), v.end(), ostream_iterator<int>(cout, ", "));
  21. }
  22. void PrintSet(unordered_set<int>& setData)
  23. {
  24.     std::copy(setData.begin(), setData.end(), ostream_iterator<int>(cout, ", "));
  25. }
  26.  
  27. vector<int> InputVector()
  28. {
  29.     vector<int> v;
  30.     string text;
  31.     getline(cin, text);
  32.     int number;
  33.     istringstream iss2(text);
  34.     while (iss2 >> number)
  35.     {
  36.         v.push_back(number);
  37.     }
  38.     return v;
  39. }
  40.  
  41. vector<vector <int> > ReadSequenceAndSeparateItBySeparators( unordered_set<int> & setSeparators)
  42. {
  43.     vector <int> dataAllNumbers = InputVector();
  44.     vector<vector <int> > dataV_Parts;
  45.     vector<int> v;
  46.     for (int i = 0; i < dataAllNumbers.size(); i++)
  47.     {
  48.         if (find(setSeparators.begin(), setSeparators.end(), dataAllNumbers[i]) == setSeparators.end())
  49.         {
  50.             v.push_back(dataAllNumbers[i]);
  51.             if (i == dataAllNumbers.size() - 1)
  52.             {
  53.                 dataV_Parts.push_back(v);
  54.                 //CHECK:
  55.                 //cout << "*****************************" << endl;
  56.                 //PrintV(v);
  57.                 cout << endl;
  58.             }
  59.         }
  60.         else
  61.         {
  62.             if (!v.empty())
  63.             {
  64.                 dataV_Parts.push_back(v);
  65.                 //CHECK:
  66.                 //cout << "*****************************" << endl;
  67.                 //PrintV(v);
  68.                 cout << endl;
  69.             }
  70.             v.clear();
  71.         }
  72.     }
  73.     return dataV_Parts;
  74. }
  75.  
  76.  
  77. int main()
  78. {
  79.     cin.sync_with_stdio(false);
  80.     cout.sync_with_stdio(false);
  81.  
  82.     vector<int> dataV_separators = InputVector();
  83.     //CHECK:
  84.     //cout << "Vector SEPARATORS: ";
  85.     //PrintV(dataV_separators);
  86.     //cout << endl;
  87.     unordered_set<int> setSeparators(dataV_separators.begin(), dataV_separators.end());
  88.     //CHECK:
  89.     //cout << "SET SEPARATORS: ";
  90.     //PrintSet(setSeparators);
  91.     //cout << endl;
  92.  
  93.    
  94.     vector < vector<int> > dataV_AllPartsOf_V_numbers = ReadSequenceAndSeparateItBySeparators(setSeparators);
  95.  
  96.     //CHECK:
  97.     /*for (auto ve : dataV_AllPartsOf_V_numbers)
  98.     {
  99.     cout << "--------------------------------" << endl;
  100.     PrintV(ve);
  101.     cout << endl;
  102.     }*/
  103.  
  104.     ostringstream output;
  105.     int numToFind;
  106.     cin >> numToFind;
  107.     while (numToFind != 0)
  108.     {
  109.         int cnt = 0;
  110.         for (auto vec : dataV_AllPartsOf_V_numbers)
  111.         {
  112.             //auto it = find(vec.begin(), vec.end(), numToFind);
  113.             if (find(vec.begin(), vec.end(), numToFind) != vec.end())
  114.             {
  115.                 cnt++;
  116.             }
  117.         }
  118.         output << cnt << endl;
  119.         cin >> numToFind;
  120.     }
  121.     cout << output.str() << endl;
  122.     return 0;
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement