Zoos

You are required to enter a word that consists of and 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 = 0i < ni++)
    {
        if (s[i] == 'z')
            x++;
        else
            break;
    }
    int y = n - x;
    if (2 * x == y)
        return "Yes";
    else
        return "No";
}
int main()
{
    string s = "zzzoooooo";

    cout << zoos(s<< "\n";

    return 0;
}


No comments:

Post a Comment