1 Replies - 269 Views - Last Post: 06 March 2013 - 05:10 PM Rate Topic: -----

#1 ThatBeast  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 36
  • Joined: 16-November 12

Single-Subscripted Array

Posted 06 March 2013 - 05:01 PM

I have to use a single-subscripted array to solve the following problem. Read in 20 numbers, each of which is between 10 and 100, inclusive. As each number is read, print it only if it is not a duplicate of a number already read. Provide for the "worst case" in which all 20 numbers are different Use the smallest possible array to solve this problem.
The file is contains these numbers:
12
12
30
12
45
66
78
30
82
19
99
11
11
15
31
18
51
17
12
17


How do I do this?

It is supposed to look like this:
The original set of numbers are: 12 12 30 12 45 66 78 30 82 19 99 11 11 15 31 18 51 17 12 17
The different numbers from the set of integers are: 12 30 45 66 78 82 19 99 11 15 31 18 51 17

This post has been edited by ThatBeast: 06 March 2013 - 05:07 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Single-Subscripted Array

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10188
  • View blog
  • Posts: 37,629
  • Joined: 27-December 08

Re: Single-Subscripted Array

Posted 06 March 2013 - 05:10 PM

If you want to use a fixed size array, an array of size 91 for elements 0-90 would work, then just flag array[element] as true as each element appears. To get a smaller array, you'll want to look into hashing algorithms.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1