U hv to enter a range from a and b and search hw many no.
of times a pattern n. occurs between the range a and b.
Eg :i/p:enter range :0 100
Enter pattern: 13
o/p: the no. times 13 occurred betwwn 0 to 100:1
Eg :i/p:enter range :100 1000
Enter pattern: 13
o/p: the no. times 13 occurred betwwn 100 to 1000:
(in this 13,113,131,132,133…139,213,313,…913 all these will
be counted)
Answer Posted / Tarun Yadav
```cppn#include <iostream>n#include <vector>n#include <algorithm>nusing namespace std;nnvoid search_pattern(int a, int b, string pattern)n{n vector<int> numbers;n for (int i = a; i <= b; ++i)n {n stringstream ss;nsstream << i;n string num = ss.str();n if (num.find(pattern) != string::npos)n {n numbers.push_back(i);n }n }nn for (int i = 0; i < numbers.size() - 1; ++i)n {n for (int j = i + 1; j < numbers.size(); ++j)n {n if (numbers[i] == pattern[0] * pow(10, numbers.size() - i - 1) + pattern[1] * pow(10, numbers.size() - i - 2) + ... + pattern[pattern.length() - 1])n {n numbers.erase(j);n --i;n break;n }n }n }nn cout << "The number of times the pattern " << pattern << " occurred between " << a << " and " << b << ":"" << numbers.size() << endl;n}nnint main()n{n int a, b;n string pattern;n cout << "Enter the range (a and b): ";n cin >> a >> b;n cout << "Enter the pattern: ";n cin >> pattern;n search_pattern(a, b, pattern);n return 0;n}n```
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
Question 1: Implement a base class Appointment and derived classes Onetime, Daily, Weekly, and Monthly. An appointment has a description (for example, “see the dentist”) and a date and time. Write a virtual function occurs_on(int year, int month, int day) that checks whether the appointment occurs on that date. For example, for a monthly appointment, you must check whether the day of the month matches. Then fill a vector of Appointment* with a mixture of appointments. Have the user enter a date and print out all appointments that happen on that date. *This Should Be Done IN C++