C++ code to check we flew to Florida more than Seattle

Suppose we have a string S with two kinds of letters 'S' and 'F'. If S[i] is 'S' we are at Seattle on ith day, and if it is 'F' we are at Florida. We have to check whether we flew more times from Seattle to Florida than Florida to Seattle.

So, if the input is like S = "SSFFSFFSFF", then the output will be True.

Steps

To solve this, we will follow these steps −

n := size of S
if S[0] is same as 'S' and S[n - 1] is same as 'F', then:
   return true
Otherwise
   return false

Example

Let us see the following implementation to get better understanding −

#include 
using namespace std;
bool solve(string S){
   int n = S.size();
   if (S[0] == 'S' && S[n - 1] == 'F')
      return true;
   else
      return false;
}
int main(){
   string S = "SSFFSFFSFF";
   cout 

Input

"SSFFSFFSFF"

Output

1
Updated on: 2022-03-15T05:32:57+05:30

114 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements