Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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&#8230;139,213,313,&#8230;913 all these will
be counted)



U hv to enter a range from a and b and search hw many no. of times a pattern n. occurs between t..

Answer / 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

More C++ Code Interview Questions

write a function -oriented program that generates the Fibonacci, the current numbers of n(as input) and display them (series). In Fibonacci, the current third number is the sum of the previous number.

3 Answers  


what is virtual constroctor ? give an exam for it?-(parimal dhimmar)

2 Answers  


readers and writers problem

1 Answers   Cognizant,


Where now stands that small knot of villages known as the Endians, a mighty forest once stood. Indeed, legand has it that you could have stoodon the edge of the wood and seen it stretch out for miles, were it not for the trees getting in the way. In one section of the forest, the trees stood in a row and were of hight from 1 to n, each hight occurring once and once only. A tree was only visible if there were no higher trees before it in the row. For example, if the heights were 324165, the only visible trees would have been those of height 3,4 & 6. Write a Program that takes an array of integers representing the heights of the trees in the row as input and prints the list of the visible trees.

2 Answers   ABC, Nagarro,


What will be the output- for(i=1;i<=3;i++) { printf("%d",i); continue; i++; }

5 Answers   Impetus,


Counting in Lojban, an artificial language developed over the last fourty years, is easier than in most languages The numbers from zero to nine are: 0 no 1 pa 2 re 3 ci 4 vo 5 mk 6 xa 7 ze 8 bi 9 so Larger numbers are created by gluing the digit togather. For Examle 123 is pareci Write a program that reads in a lojban string(representing a no less than or equal to 1,000,000) and output it in numbers.

4 Answers  


write a program that reads a series of strings and prints only those strings begging with letter "b"

1 Answers  


Write a program using one dimensional array that searches a number and display the number of times it occurs on the list of 12 input values. Sample input/output dialogue: Enter 12 values: 13 15 20 13 30 35 40 16 18 20 18 20 Enter number to search: 20 Occurences: 3

2 Answers  


An array of size 5X5 is given to us. The elements from 1 to 25 are to be inserted in the array, such that starting from a particular position for an element i, the next element i+1can be inserted only at the mentioned positions (u,v), and if these all positions are occupied then it returns giving a count of how many positions have been occupied in the array: (u,v) = (x+/-3 , y) (u,v) = (x , y+/-3) (u,v) = (x+/-2 , y+/-2). Example: if the starting element is 1 with the given positions (1,2), then next element 2 can be placed at any one of the positions marked with *. _ _ _ _ _ 1 _ _ _ * _ _ _ _ _ _ _ * _ _ * _ _ _ _

0 Answers   Nagarro,


Min-Max Write an algorithm that finds both the smallest and largest numbers in a list of n numbers and calculate its complexity T(n).

1 Answers   Infosys, Qatar University,


What output does the following code generate? Why? What output does it generate if you make A::Foo() a pure virtual function? class A { A() { this->Foo(); } virtual void Foo() { cout << "A::Foo()" << endl; } }; class B : public A { B() { this->Foo(); } virtual void Foo() { cout << "A::Foo()" << endl; } }; int main(int, char**) { A objectA; B objectB; return 0; }

1 Answers  


Given 1 to n random number, find top 10 maximum numbers and explain the time complexity of the algorithm.

1 Answers   IMO, NetApp,


Categories