Input: 30 30 30 40 40 50 50 4 4 4 4
output: 3 30 2 40 2 50 4 4
I have to accept these integer numbers and display the count of each unique number with the number beside the count.
I honestly don't know what condition to give to accept only till the last integer 4 of the input and not accept infinitely or some garbage values. Because all test cases do not have the same number of values as input. Please explain what function/logic I need to use to just accept the finite numbers of integers.
I used a for loop that accepted and stored values in a vector for 99 times, because the question said that the maximum number of integers that I can accept is 99. But for the above test case, 11 required integers are accepted and the rest 87 are garbage/last integer values...
It accepted 30 30 30 40 40 50 50 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 .........(till the 99th loop)
(I would've attached a screenshot of what I did if I could. I didn't do that because, 1) I was asked to code this in a contest so I don't remember the exact question as we were not allowed to bring our rough sheets out with us. 2) I couldn't make a decent attempt to solve it as I didn't even know how to accept the integers without accepting garbage values. Sorry for the uncertainty!)