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

Username:   Password: 
 RegisterRegister   
 Mode of chracters
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
eNc




PostPosted: Sun Feb 06, 2005 12:45 pm   Post subject: Mode of chracters

Hi, umm i was wondering how i would go about finding the mode of chracters in string

ie -- INPUT = 139523442133
code:

for  i  : 1..length(InputString)
        do something to find the mode (most freqent)
        character
        put mode
        %this would output 3
end for
Sponsor
Sponsor
Sponsor
sponsor
TheZsterBunny




PostPosted: Sun Feb 06, 2005 4:36 pm   Post subject: (No subject)

hrm. it would make for difficulty if you were using more than one digit numbers. however;

code:

var numstring := "139523442133"
var numcount : array 0 .. 9 of int := init (0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
for i : 1 .. length (numstring)
    numcount (strint (numstring (i))) += 1
end for
var mode, modemax : int := 0
for i : 0 .. 9
    if numcount (i) > modemax then
        modemax := numcount (i)
        mode := i
    end if
end for
put "The number ", mode, " occurred ", modemax, " times in ", numstring, "."

would give you the mode for single-digit numbers

-Z

lol. while writing the code, i kept having to delete the java statements and replace them with turing.
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  [ 2 Posts ]
Jump to:   


Style:  
Search: