Acm (UVa) : 499

What’s The Frequency, Kenneth?

Data type:
Character / String + Integer

Declare an Integer array of 52 elements. 26 elements for (a-z) and rest 26 elements for (A-Z).
Firstly, Initialize (0) to all elements of array.
Then scan the string, whenever u find an alphabet, increment the relevant array element.
At last, find the maximum number in array and print the number with it’s relevant character.

For instance, lets our string is: “aaceecceec”

so, Array [1] = 2 // Array [1] represents the number of occurrence of character ‘a’
Array [2] = 0 // As, there is no ‘b’ in our string.
Array [3] = 4 // we have found ‘c’ 4 times
Array [4] = 0 // no ‘d’
Array [5] = 4 // number of occurrence of ‘e’
output: ce 4 // as ‘c’ and ‘e’ both have same number of occurrence and maximum.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s