You are required to enter a word that consists of x and y that denote the number of Zs and Os respectively. The input word is considered similar to the word zoo if
2*x=y
Determine if the entered word is similar to the word zoo.
Example:
Input: s= "zzzoooooo"
Output: Yes
Approach
C++
#include <bits/stdc++.h>using namespace std;string zoos(string s){int n = s.size();int x = 0;for (int i = 0; i < n; i++){if (s[i] == 'z')x++;elsebreak;}int y = n - x;if (2 * x == y)return "Yes";elsereturn "No";}int main(){string s = "zzzoooooo";cout << zoos(s) << "\n";return 0;}
No comments:
Post a Comment