how to find and change duplicates in array?
Author |
Message |
we64
![](http://i5.photobucket.com/albums/y174/we64/LJDisplayPicture.jpg)
|
Posted: Thu Feb 05, 2004 6:27 pm Post subject: how to find and change duplicates in array? |
|
|
If I have 10 random numbers between 1 to 15, such as 5,6,2,10,14,10,5,3,2,1. How do I replace the duplicate numbers? |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
|
|
|
![](images/spacer.gif) |
recneps
![](http://www.fcpocanada.com/canada1.gif)
|
Posted: Thu Feb 05, 2004 6:43 pm Post subject: (No subject) |
|
|
store them in an array,
and then go through each array number.
like
code: |
for a:1..15%makes it go throught a loop for each number.
for i:1..15%compares the number from large loop to each of the numbers.
if number(i)=number(a) and i not = a then
put "number ",i," is the same as number (3)."
end for
end for | try that ![Smile Smile](http://compsci.ca/v3/images/smiles/icon_smile.gif) |
|
|
|
|
![](images/spacer.gif) |
sport
![](http://www.members.shaw.ca/rfolz/e17661eqn7y.jpg)
|
Posted: Thu Feb 05, 2004 6:45 pm Post subject: (No subject) |
|
|
Here is a program how to create ten unique numbers, hope it helps you.
code: |
var num : array 1 .. 10 of int
for i : 1 .. 10
num (i) := 0
end for
var temp : int
var exist : boolean
for i : 1 .. 10
randomize
loop
exist := false
randint (temp, 1, 15)
for j : 1 .. 10
if num (j) = temp then
exist := true
exit
end if
end for
if exist = false then
num (i) := temp
end if
exit when exist = false
end loop
end for
for i : 1 .. 10
put num (i)
end for
|
|
|
|
|
|
![](images/spacer.gif) |
we64
![](http://i5.photobucket.com/albums/y174/we64/LJDisplayPicture.jpg)
|
Posted: Thu Feb 05, 2004 8:01 pm Post subject: (No subject) |
|
|
thanks guys |
|
|
|
|
![](images/spacer.gif) |
|
|