how to find and change duplicates in array?
Author |
Message |
we64
|
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? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Tony
|
|
|
|
|
recneps
|
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 |
|
|
|
|
|
sport
|
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
|
|
|
|
|
|
|
we64
|
Posted: Thu Feb 05, 2004 8:01 pm Post subject: (No subject) |
|
|
thanks guys |
|
|
|
|
|
|
|