# 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.) May 21, 2015 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. May 21, 2015 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? May 21, 2015 at 14:37
• Is a single trailing space okay? May 21, 2015 at 15:19
• Use the Sandbox for Proposed Challenges. May 22, 2015 at 1:09

# Arn -a, 22 bytes

(Ø-═É┤<LO¼‚R€Ê■ÊÕ'à¦┴%


-a encloses the final array, separating the strings by spaces.

Uncompressed: :s@+{"AEIOUaeiou":i&!!1+}\

Arn has some trouble with strings, so this is a bit long.

you can omit the -u flag to give input directly through STDIN.

-13 bytes from Zippymagician.

• :s@+{"AEIOUaeiou":i>=0}\ is 2 bytes shorter. May 11, 2021 at 12:05

# AWK, 42 bytes

BEGIN{RS=ORS=FS}$0=gsub(/[aeiouAEIOU]/,e)e  Try it online! Regards each word as a different record (i.e., line), and substitute them for the count of vowels, calculated by the substitution function gsub. e is a dummy null variable, that, when appended to the number, makes awk parse it as string, so zero can be printed. # Vyxal, 6 bytes ⌈ƛk∨↔L  Try it Online! Explanation:  # Implicit input ⌈ # Split input on ' ' ƛ # For each word in input: k∨↔ # Remove all non-vowels L # Length of resulting string # Implicit output  # Vyxal, 4 bytes ⌈ƛA∑  Try it Online! ⌈ # Split on spaces ƛ # Map... A # Vowel mask (1 for vowel, 0 for not) ∑ # Sum  # C# 186 public class a{public static void Main(string[] a){Console.Write(string.Join(" ",Console.ReadLine().Split(' ').Select(x=>x.ToCharArray().Count(y=>"aeoui".ToCharArray().Contains(y)))));}}  • This fails for the third test case. Your program doesn't seem to count AEIOU. Jun 20, 2015 at 6:05 # 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!

# Japt v2.0a0, 5 bytes

mè\vS


Try it

# Python 3.8 (pre-release), 106 bytes

for x in input().upper().split():
p=0
for y in x:
if 1065233>>(ord(y)-65)&1:
p+=1
print(p,end=" ")


Ehh, fairly long solution, but it's a start

Try it online!