PROBLEM LINK:
Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4
Author: notsoloud
Tester: mexomerf
Editorialist: iceknight1093
DIFFICULTY:
TBD
PREREQUISITES:
None
PROBLEM:
Given a string S of length 8, you can modify any of its consonants to other consonants and any vowels to other vowels.
Can S be turned into \texttt{CODETOWN}?
EXPLANATION:
Let T = \texttt{CODETOWN} be our target string.
Then, for each i from 1 to 8:
- If S_i is a vowel:
- If T_i is a vowel, we can turn S_i into T_i with one move.
- If T_i is a consonant, there’s no way to turn S_i into T_i.
- If S_i is a consonant:
- If T_i is a consonant, we can turn S_i into T_i with one move.
- If T_i is a vowel, again there’s no way to turn S_i into T_i.
If either of the above checks fail for any index (i.e, S_i is a vowel and T_i is a consonant, or vice versa), the answer is No
.
Otherwise, the answer is Yes
.
TIME COMPLEXITY:
\mathcal{O}(1) per testcase.
CODE:
Editorialist's code (Python)
vowels = 'AEIOU'
target = 'CODETOWN'
for _ in range(int(input())):
s = input()
ans = 'Yes'
for i in range(8):
if target[i] in vowels and s[i] not in vowels: ans = 'No'
if target[i] not in vowels and s[i] in vowels: ans = 'No'
print(ans)