Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 01_03_Task3_Code_FAST_3.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream> //for std::cout
- #include <string>
- #include <sstream>
- #include <iomanip>
- #include <vector>
- #include <iterator> //for std::ostream_iterator
- #include <algorithm> //for std::copy
- #include <utility> //pair<vey, value>
- #include <set>
- #include <unordered_set>
- using namespace std;
- void PrintV(vector<int> v)
- {
- std::copy(v.begin(), v.end(), ostream_iterator<int>(cout, ", "));
- }
- void PrintSet(unordered_set<int>& setData)
- {
- std::copy(setData.begin(), setData.end(), ostream_iterator<int>(cout, ", "));
- }
- vector<int> InputVector()
- {
- vector<int> v;
- string text;
- getline(cin, text);
- int number;
- istringstream iss2(text);
- while (iss2 >> number)
- {
- v.push_back(number);
- }
- return v;
- }
- vector<vector <int> > ReadSequenceAndSeparateItBySeparators( unordered_set<int> & setSeparators)
- {
- vector <int> dataAllNumbers = InputVector();
- vector<vector <int> > dataV_Parts;
- vector<int> v;
- for (int i = 0; i < dataAllNumbers.size(); i++)
- {
- if (find(setSeparators.begin(), setSeparators.end(), dataAllNumbers[i]) == setSeparators.end())
- {
- v.push_back(dataAllNumbers[i]);
- if (i == dataAllNumbers.size() - 1)
- {
- dataV_Parts.push_back(v);
- //CHECK:
- //cout << "*****************************" << endl;
- //PrintV(v);
- cout << endl;
- }
- }
- else
- {
- if (!v.empty())
- {
- dataV_Parts.push_back(v);
- //CHECK:
- //cout << "*****************************" << endl;
- //PrintV(v);
- cout << endl;
- }
- v.clear();
- }
- }
- return dataV_Parts;
- }
- int main()
- {
- cin.sync_with_stdio(false);
- cout.sync_with_stdio(false);
- vector<int> dataV_separators = InputVector();
- //CHECK:
- //cout << "Vector SEPARATORS: ";
- //PrintV(dataV_separators);
- //cout << endl;
- unordered_set<int> setSeparators(dataV_separators.begin(), dataV_separators.end());
- //CHECK:
- //cout << "SET SEPARATORS: ";
- //PrintSet(setSeparators);
- //cout << endl;
- vector < vector<int> > dataV_AllPartsOf_V_numbers = ReadSequenceAndSeparateItBySeparators(setSeparators);
- //CHECK:
- /*for (auto ve : dataV_AllPartsOf_V_numbers)
- {
- cout << "--------------------------------" << endl;
- PrintV(ve);
- cout << endl;
- }*/
- ostringstream output;
- int numToFind;
- cin >> numToFind;
- while (numToFind != 0)
- {
- int cnt = 0;
- for (auto vec : dataV_AllPartsOf_V_numbers)
- {
- //auto it = find(vec.begin(), vec.end(), numToFind);
- if (find(vec.begin(), vec.end(), numToFind) != vec.end())
- {
- cnt++;
- }
- }
- output << cnt << endl;
- cin >> numToFind;
- }
- cout << output.str() << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement