Question:
Write a program that reads through a text file and finds the word that has the most consecutive vowels.?
anonymous
1970-01-01 00:00:00 UTC
Write a program that reads through a text file and finds the word that has the most consecutive vowels.?
Three answers:
?
2016-08-07 10:45:00 UTC
Well, you already know what the vowels are right? So you parse thru the input checking out for the occurance of ur situation(ie: being a vowel) do not hate cuz I dont put up the code..You put up united states of americafirst and we are going to help debug. Its now not My undertaking
Todd
2013-05-30 07:21:53 UTC
Okay, obviously the easiest approach is to just keep comparing from a list of words, searching each word and keeping a running highest.



I didn't do it this way. I also didn't use Java, so this answer won't help you, but I just _had_ to tackle this one. The magic is in using a regular expression and hash. I used ruby on a words list supplied with a linux distro. We're assuming y is not included.



### BEGIN



string = File.open('word_list.txt', 'r') {|file| file.read} #read in the file

word_list = string.split

tally = {} #initialize our hash



#the next line sets up the hash, scan gives all consecutive occurrences of the

#vowels in the word and grabs the max for that word

word_list.each {|word| tally[word] = ((word.scan /\a*[aeiou]+\a*/).map &:size).max}



tally.reject! {|k, v| !v} #get rid of words/abbreviations with no vowels like wryly

max = tally.values.max

vowel_winners = tally.select {|word, vowel_count| vowel_count == max}

puts vowel_winners



### END



Incidentally, the result is...

{"cooeeing"=>5, "miaoued"=>5, "miaouing"=>5, "queueing"=>5}



The only word Merriam-Webster accepts is queueing. This isn't surprising, since the linux words list often contains words that have obscure spellings or are not technically english words.



Edit... oops, forgot the 'e' in queueing while typing the answer. Fixed it now :)
Bob
2013-05-29 04:18:13 UTC
Use similar logic :



http://pastebin.com/Er7T5RCk



read the first word and set it to be the word with the most vowels. Then read the other words and compare the number of vowels, if the first word has more vowels than the second keep the first word as the word with the most vowels else make the second word as the word with the most vowels... and continue the loop ! Hope this helps ...



------------------

You are here to learn , we can't solve your problems for you ... so the logic is

we have the following words (woohooo - basic - chainz - vodoooo - similar)

we read "woohooo"

mWord = "woohooo"

count = 0; (count is like maxVowels and maxVowelsnew)

we loop over its characters ... one by one ...

w - not a vowel

o - a vowel ... so now we increment the count.. count+1

now we could do a while loop ... while(o isn't the last character in the word and next character is a vowel) we increment count.

so count = 2.

you could have also an array of 1 element. if this array is empty ... place 2 in it.

now we continue ... h - not a vowel

o- a vowel ... we start a new count =0... increment it by 1 ... while loop ... now

count=3 after the while loop terminates .. we compare 3 with the array ... 3>2 so we place 3

in the array.

we move to another word and do the same .. and mword is only changing when a word with more

consecutive vowels is found. Hope this helps !


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...