Multiple Counters Summary
Python
Hard
2 views
Problem Description
Read n words. Maintain two counters: vowelStart and consonantStart. Increment depending on first letter of each word. Output both counts.
Input Format
First line n. Next n lines: word.
Output Format
One line: vowelStart consonantStart.
Sample Test Case
Input:
5
apple
bat
ice
zoo
orange
Official Solution
import sys
lines=sys.stdin.read().splitlines()
if not lines or not lines[0].strip():
sys.exit(0)
n=int(lines[0].strip())
v=0
c=0
vow=set('aeiouAEIOU')
for i in range(1,1+n):
w=(lines[i] if i<len(lines) else '').strip()
if not w: continue
if w[0] in vow:
v+=1
else:
c+=1
sys.stdout.write(f"{v} {c}")
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!