Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
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 −
#includeusing 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
Advertisements
