PROBLEM LINK:
Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4
Author: iceknight1093
Tester: iceknight1093
Editorialist: iceknight1093
DIFFICULTY:
Cakewalk
PREREQUISITES:
None
PROBLEM:
A drink is called fanta-like if its name ends with -nta.
You purchased a drink with the name S, which is a 5-letter word.
Is it fanta-like?
EXPLANATION:
We need to check if the last three characters of S are n, t, a in that exact order.
We also know that S has a length of exactly 5.
So, assuming that S is 1-indexed, the checks that need to be made are:
- S_3 = \tt{n}
- S_4 = \tt{t}
- S_5 = \tt{a}
If all three checks pass, the answer is Yes, otherwise the answer is No.
If you use 0-indexing instead, the respective checks will be:
- S_2 = \tt{n}
- S_3 = \tt{t}
- S_4 = \tt{a}
TIME COMPLEXITY:
\mathcal{O}(1) per testcase.
CODE:
Editorialist's code (PyPy3)
s = input()
if s[2] == 'n' and s[3] == 't' and s[4] == 'a': print('Yes')
else: print('No')