Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 01_03_Task3_Code.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 <vector>
- #include <utility> //pair<vey, value>
- using namespace std;
- int main()
- {
- cin.sync_with_stdio(false);
- cout.sync_with_stdio(false);
- string line;
- getline(cin, line);
- vector<string> data_V_strSeparators;
- string strToken;
- istringstream iss(line);
- while (iss >> strToken)
- {
- data_V_strSeparators.push_back(strToken);
- }
- string text;
- getline(cin, text);
- for (auto n : data_V_strSeparators)
- {
- int pos = text.find(n);
- while (pos != string::npos)
- {
- text.replace(pos, n.size(), "*");
- pos = text.find(n, pos + 1);
- }
- }
- //CHECK:
- //cout << text << endl;
- text += "*";
- string strNumToFind;
- getline(cin, strNumToFind);
- int cnt = 0;
- while (strNumToFind != "0")
- {
- int firstIndexOfNumberToFind = text.find(strNumToFind, 0);
- if (firstIndexOfNumberToFind == string::npos)
- {
- cout << 0 << endl;
- getline(cin, strNumToFind);
- continue;
- }
- int firstIndexOfStar = text.find("*", 0);
- if (firstIndexOfNumberToFind < firstIndexOfStar)
- {
- cnt = 0;
- int indexOfOccurence = firstIndexOfNumberToFind;
- cnt++;
- while (indexOfOccurence != string::npos)
- {
- indexOfOccurence = text.find("*", indexOfOccurence + strNumToFind.size());
- indexOfOccurence = text.find(strNumToFind, indexOfOccurence + 1);
- if (indexOfOccurence != string::npos)
- {
- cnt++;
- }
- else
- {
- cout << cnt << endl;
- break;
- }
- }
- }
- else
- {
- cnt = 0;
- int indexOfOccurence = firstIndexOfStar;
- while (indexOfOccurence != string::npos)
- {
- indexOfOccurence = text.find(strNumToFind, indexOfOccurence + 1);
- if (indexOfOccurence != string::npos) {
- cnt++;
- }
- else
- {
- cout << cnt << endl;
- break;
- }
- indexOfOccurence = text.find("*", indexOfOccurence + strNumToFind.size());
- //CHECK:
- //cout << "count: " << cnt << "Index of *: " << indexOfOccurence << endl;
- }
- }
- getline(cin, strNumToFind);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement