Read a list of ints into a array.The output is two-column list,first column is a list of the different
array elements ;second column is the count of that element occurs.We can assume that there are few than 50 ints.
Ok,the only problem for me is how to count the ints.Compare to letters,I can set up a array called letters,then contain from a~z,and use get function to get the char and compare:
so you can see in my count,I have the occurences.
but how to deal with an arbitrary int?
1. Read your numbers into the array.
2. Sort the array.
3. Start at the first element.
4. Call the count STL function on that array for the current element we are looking at. Print the element and the count returned.
5. Advance through the array the same number of positions as step 4 returned
5A. If not at the end of the array return to step 4.
5B. If we are at the end, then exit.
Do you have to use an array? It becomes pretty trivial with a std::map. In fact, it would be what you described with letters, except that it is still efficient when dealing with arbitrary ints.
Yeah, I naturally thought that too, but he said "Read a list of ints into a array" so I worked with what I got.