# Count the number of vowels in each word of a string

This is a rather easy challenge.

# Challenge

Input will contain a string (not null or empty) of maximum length 100. Output the number of vowels in each word of the string, separated by spaces.

# Rules

• The string will not be more than 100 characters in length.
• The string will only contain alphabets A-Z , a-z and can also contain spaces.
• Input must be consumed from the stdin or command line arguments.
• Output must be outputted in the stdout.
• You can write a full program, or a function that takes input from the stdin and outputs the result.
• The vowels that your program/function needs to count are aeiou and AEIOU.

# Test Cases

This is the first test case     --> 1 1 1 1 1 2
one plus two equals three       --> 2 1 1 3 2
aeiou AEIOU                     --> 5 5
psst                            --> 0
the quick brown fox jumped over the lazy dog --> 1 2 1 1 2 2 1 1 1


# Scoring

This is , so the shortest submission (in bytes) wins.

• Is there a reason why you insist on a rather restrictive I/O format? Not every language can (conveniently) interact with STDIN and STDOUT. We have defaults for this (which you are of course free to override if you wish), which also allow command-line argument, function argument, return value etc. (They can also be found in the tag wiki.) – Martin Ender May 21 '15 at 10:58
• @MartinBüttner , "Is there a reason why you insist on a rather restrictive I/O format?" -- No. I just like stdin with stdout. I don't like to "get input" via the function arguments. command-line arguments seems ok. I've added it into the post. – Spikatrix May 21 '15 at 11:04
• WIKIPEDIA: The name "vowel" is often used for the symbols that represent vowel sounds in a language's writing system, particularly if the language uses an alphabet. In writing systems based on the Latin alphabet, the letters A, E, I, O, U, and sometimes Y are all used to represent vowels. However, not all of these letters represent vowels in all languages. What do YOU mean by vowels? – edc65 May 21 '15 at 14:37
• Is a single trailing space okay? – Alex A. May 21 '15 at 15:19
• Use the Sandbox for Proposed Challenges. – mbomb007 May 22 '15 at 1:09

# K (oK), 22 bytes

Solution:

(+/,/"aeiou"=\:)'" "\_


Try it online!

Examples:

> (+/,/"aeiou"=\:)'" "\_"This is the first test case"
1 1 1 1 1 2
> (+/,/"aeiou"=\:)'" "\_"aeiou AEIOU"
5 5


Explanation:

Interpretted right-to-left, lowercase input, split on whitespace, then check each word against each vowel, flatten and sum results:

(+/,/"aeiou"=\:)'" "\_ / the solution
_ / convert to lowercase
" "\  / split on " "
'      / each
(              )       / do all this together
"aeiou"=\:        / check each-left (\:) "aeiou" equal (=) to right argument
,/                  / flatten
+/                    / sum


# Java 8, 137 135 bytes

As full program:

interface M{static void main(String[]a){for(String s:a[0].split(" "))System.out.print(s.replaceAll("[^aeiouAEIOU]","").length()+" ");}}


Try it here.

As function:

A full program is apparently shorter than a function in this case (137 bytes):

v->{for(String s:new java.util.Scanner(System.in).nextLine().split(" "))System.out.print(s.replaceAll("[^aeiouAEIOU]","").length()+" ");}


Try it here.

Explanation:

interface M{                       // Class
static void main(String[]a){     //  Mandatory main-method
for(String s:a[0].split(" "))  //   Loop over the words of the input:
System.out.print(s.replaceAll("[^aeiouAEIOU]","")
//    Remove every non-vowel,
.length()  //    and print the length of the remainder
+" ");      //    + a space
//   End of loop (implicit / single-line body)
}                                //  End of main-method
}                                  // End of class


## Perl 5, 23 bytes

19 bytes code + 4 for -p040.

$_=lc=~y/aeiou//.$"


Try it online!

# Common Lisp, 74 bytes

(loop as i =(read)do(print(count-if(lambda(x)(find x"AEIOU"))(string i))))


Try it online!