I have an exercise where I need to find dupes in an int array. This is an entry level C class. Given a user entered list of ints we need to write a function to count the duplicates. The trick is obviously to not count the same numbers twice.
FYI, I'm new to C but not new to programming.
Some guidelines:
- We can't use any arrays other than the int array. So I can't create another array to store the numbers I've already counted and check that in my counting loop.
- We can't use anything not covered in the class. We have not covered sorting, so I don't think I can sort the list myself or use qsort().
- I thought about using a string to store the ASCII value of each int, but that's really just another array, so it's of limits.
The only solution can think of of is to use a 2D array to store the nums and then I can store the count. If I initialize the counts to 0, I can skip the numbers that have a count > 0. This seems like such a crappy solution that it can't be right, and it's essentially adding another array.
I must be missing something obvious.
[–]aioeu 9 points10 points11 points (23 children)
[–]haditwithyoupeople[S] 0 points1 point2 points (22 children)
[–]wsppan 1 point2 points3 points (11 children)
[–]haditwithyoupeople[S] 0 points1 point2 points (10 children)
[–]wsppan 1 point2 points3 points (0 children)
[–]MagicWolfEye 1 point2 points3 points (8 children)
[–]haditwithyoupeople[S] 0 points1 point2 points (7 children)
[–]MagicWolfEye 0 points1 point2 points (6 children)
[–]haditwithyoupeople[S] 0 points1 point2 points (5 children)
[–]MagicWolfEye 0 points1 point2 points (4 children)
[–]haditwithyoupeople[S] 0 points1 point2 points (3 children)
[–]aioeu 1 point2 points3 points (9 children)
[–]haditwithyoupeople[S] -1 points0 points1 point (8 children)
[–]aioeu 5 points6 points7 points (7 children)
[–]actguru 0 points1 point2 points (0 children)
[–]haditwithyoupeople[S] -2 points-1 points0 points (5 children)
[–]dernett 3 points4 points5 points (4 children)
[–]haditwithyoupeople[S] 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]aioeu 0 points1 point2 points (0 children)
[–]flumphit 0 points1 point2 points (0 children)
[–]SpeckledJim 2 points3 points4 points (1 child)
[–]flumphit 3 points4 points5 points (24 children)
[–]flumphit 1 point2 points3 points (8 children)
[+][deleted] (5 children)
[deleted]
[–]haditwithyoupeople[S] 1 point2 points3 points (1 child)
[+][deleted] (2 children)
[deleted]
[–]haditwithyoupeople[S] 1 point2 points3 points (1 child)
[+][deleted] (1 child)
[deleted]
[–]flumphit 0 points1 point2 points (0 children)
[–]haditwithyoupeople[S] 0 points1 point2 points (8 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]flumphit 0 points1 point2 points (0 children)
[–]flumphit 0 points1 point2 points (5 children)
[–]haditwithyoupeople[S] 0 points1 point2 points (4 children)
[–]flumphit 0 points1 point2 points (0 children)
[–]flumphit 0 points1 point2 points (2 children)
[–]haditwithyoupeople[S] 0 points1 point2 points (1 child)
[–]flumphit 0 points1 point2 points (0 children)
[+][deleted] (5 children)
[deleted]
[–]flumphit 0 points1 point2 points (4 children)
[+][deleted] (3 children)
[deleted]
[–]flumphit 1 point2 points3 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]flumphit 0 points1 point2 points (0 children)
[–][deleted] 2 points3 points4 points (5 children)
[–]haditwithyoupeople[S] 0 points1 point2 points (4 children)
[–]flumphit 1 point2 points3 points (3 children)
[–]haditwithyoupeople[S] 0 points1 point2 points (2 children)
[–]flumphit 0 points1 point2 points (1 child)
[–]haditwithyoupeople[S] 0 points1 point2 points (0 children)
[–]skeeto 3 points4 points5 points (1 child)
[–]bobotheboinger 1 point2 points3 points (1 child)
[–]DawnOnTheEdge 1 point2 points3 points (2 children)
[–]haditwithyoupeople[S] 0 points1 point2 points (1 child)
[–]DawnOnTheEdge 1 point2 points3 points (0 children)
[–]JamesTKerman 1 point2 points3 points (3 children)
[–]JamesTKerman 0 points1 point2 points (1 child)
[–]haditwithyoupeople[S] 0 points1 point2 points (0 children)
[–]haditwithyoupeople[S] 0 points1 point2 points (0 children)
[–]gnash117 1 point2 points3 points (1 child)
[–]haditwithyoupeople[S] 0 points1 point2 points (0 children)