Advertisement
Guest User

03_Task3_Code

a guest
Jul 16th, 2018
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.14 KB | None | 0 0
  1. // 01_03_Task3_Code.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. int main()
  23. {
  24.     cin.sync_with_stdio(false);
  25.     cout.sync_with_stdio(false);
  26.  
  27.     string line;
  28.     getline(cin, line);
  29.     unordered_set<int> setSeparators;
  30.  
  31.     int token;
  32.     istringstream iss(line);
  33.     while (iss >> token)
  34.     {
  35.         setSeparators.insert(token);
  36.     }
  37.     //CHECK:   
  38.             //cout << "DELIMITERS: " ;
  39.             //PrintV(data_V_separators);
  40.             //cout << endl;
  41.  
  42.     string text;
  43.     getline(cin, text);
  44.     int number;
  45.     /*iss.str("");
  46.     iss.clear();
  47.     iss(text);*/
  48.     istringstream iss2(text);
  49.     vector<int> dataAllNumbers;
  50.     while (iss2 >> number)
  51.     {
  52.         dataAllNumbers.push_back(number);
  53.     }
  54.  
  55.     vector < vector<int> > dataV_AllPartsOf_V_numbers; 
  56.     vector<int> v;
  57.     for (int i = 0; i < dataAllNumbers.size(); i++)
  58.     {
  59.         if (find(setSeparators.begin(), setSeparators.end(), dataAllNumbers[i]) == setSeparators.end())
  60.         {
  61.             v.push_back(dataAllNumbers[i]);
  62.             if (i == dataAllNumbers.size() - 1)
  63.             {
  64.                 if (!v.empty())
  65.                 {
  66.                     dataV_AllPartsOf_V_numbers.push_back(v);
  67.                 }
  68.             }
  69.         }
  70.         else
  71.         {
  72.             if (!v.empty())
  73.             {
  74.                 dataV_AllPartsOf_V_numbers.push_back(v);
  75.             }
  76.             v.clear();
  77.         }
  78.     }
  79.     //CHECK:
  80.         /*for (auto ve : dataV_AllPartsOf_V_numbers)
  81.         {
  82.             cout << "--------------------------------" << endl;
  83.             PrintV(ve);
  84.             cout << endl;
  85.         }*/
  86.     ostringstream output;
  87.     int numToFind;
  88.     cin >> numToFind;
  89.     while (numToFind != 0)
  90.     {
  91.         int cnt = 0;
  92.         for (auto vec : dataV_AllPartsOf_V_numbers)
  93.         {
  94.             //auto it = find(vec.begin(), vec.end(), numToFind);
  95.             if (find(vec.begin(), vec.end(), numToFind) != vec.end())
  96.             {
  97.                 cnt++;
  98.             }
  99.         }
  100.         output << cnt << endl;
  101.         cin >> numToFind;
  102.     }
  103.     cout << output.str() << endl;
  104.     return 0;
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement