Untitled
unknown
python
3 years ago
1.2 kB
6
Indexable
import sys
VOWELS = "AEIOU"
def find_min_seconds(word):
if len(word) == 1: return 0
counter_map = {}
total_vowels = 0
total_consonants = 0
for letter in word:
if letter not in counter_map:
counter_map[letter] = 0
counter_map[letter] += 1
if letter in VOWELS:
total_vowels += 1
else:
total_consonants += 1
min_seconds = -1
if total_vowels == 0:
min_seconds = total_consonants
elif total_consonants == 0:
min_seconds = total_vowels
for letter in counter_map:
if letter in VOWELS:
seconds = (total_vowels - counter_map[letter]) * 2
seconds += total_consonants
else:
seconds = (total_consonants - counter_map[letter]) * 2
seconds += total_vowels
if seconds < min_seconds or min_seconds == -1:
min_seconds = seconds
return min_seconds
def main(input):
total_cases = int(next(input))
for i in range(total_cases):
word = str(next(input)).strip()
result = find_min_seconds(word)
print(f"Case #{i+1}: {result}")
if __name__ == '__main__':
main(sys.stdin)
Editor is loading...