Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 how to find and change duplicates in array?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
we64




PostPosted: 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
Sponsor
sponsor
Tony




PostPosted: Thu Feb 05, 2004 6:39 pm   Post subject: (No subject)

just generate a unique list with this code
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
recneps




PostPosted: 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
sport




PostPosted: 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




PostPosted: Thu Feb 05, 2004 8:01 pm   Post subject: (No subject)

thanks guys
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: