Codechef Problems: Fonta (FONTA)
Problem Statement:
https://www.codechef.com/problems/FONTA
Solution:
Given,
A drink is called fanta-like if it has its last 3 characters
‘nta’
Condition, it is guaranteed that input string has 5
characters
To find, whether the input string is fanta-like or not
To solve this problem we first need to check whether the
input string has five characters or not
Condition : If length of input string is not 5
Output : NO
After this we need to find whether the input string has last
three characters ‘n’, ‘t’ and ‘a’ respectively
Condition 1 : If last 3rd character = n and last
2nd character = t and last character = a
Output : YES
Condition 2 : otherwise
Output : NO
Code Solution:
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
cin >> str;
if (str.length()
!= 5) {
cout <<
"NO" << endl;
return 0;
}
if (str[2] == 'n'
&& str[3] == 't' && str[4] == 'a') {
cout <<
"YES" << endl;
} else {
cout <<
"NO" << endl;
}
return 0;
}
Comments
Post a Comment