-
Occurence counter
Hi,
I am a new user of C++ and I am learning this language.
I want to resolve this example:
1) I have an indefinite sequence of integer (from 0 to 36) as Input;
2) I want to know the maximum number of occurrences and its value.
Sample
Input: 0, 2, 5, 2, 23, 11, 11, 23, 15, 17, 25, 11, 23, 18, 23 (Ctrl+z)
Output: Value is 23 Occurences is 4
For the input I have written this code:
Code:
iNumber = 0; // Counter
while (1)
{ //read next
cout << "Enter number (Ctrl-z = Input End): ";
cin >> myNumber;
if (cin.eof())
break;
//update the counter
iNumber++;
}
But I am in difficulty, when :mad: I try to resolve the second step. The
solution don't have to use the array/map/struct.
;) I hope in Your help in order to resolve my problem.
Thank You and Best Regards
Nino
-
Err ... I really don't think this is possible to solve without either a simple array or lots of variables and a very ugly switch to simulate it. Oh, and the latter solution would have a quite horrible tree of ifelses to find the maximum.
-
Maybe the exact citate from the assignment would help? I suppose that only class implementations of vector, map etc are forbidden, but use of regular C-style arrays is possible...
-
I tested a solution that used the sort and equal_range and distance STL functions along with a regular integer array. Can you use those functions?
-
Yes, I can use this.
Thank You.
Nino