- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 <bits/stdc++.h> 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 << solve(S) << endl; }
Input
"SSFFSFFSFF"
Output
1
Advertisements