Codechef Problems: Snaky Strings (SSNK)
Problem Statement:
https://www.codechef.com/problems/SSNK
Solution:
Given, a string is called ‘snaky’ if it starts or ends with the
letter ‘s’
Input
string is of length 4
To find, whether the input string is snaky or not
To solve the above problem first we need to check whether
the input string has length 4 or not
Condition : length of input string is not 4
Output : NO
Then, we need to find whether the string starts or ends with
letter ‘s’
Condition 1 : string[0] == ‘s’ or string[3] == ‘s’
Output: YES
Condition 2 : otherwise
Output: NO
Code Output:
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
cin >> str;
if (str.length()
!= 4) {
cout <<
"No" << endl;
}
if (str[0] == 's'
|| str[3] == 's') {
cout <<
"Yes" << endl;
} else {
cout <<
"No" << endl;
}
return 0;
}
Comments
Post a Comment