Uva 10324 - Zeros and Ones

/*

Very Easy Brute force Problem. Just take a string of C++ and for each query check whether all characters are same from minimum query to maximum query. If not store in a vector as No otherwise store as Yes. At last print that loop. Be careful about the empty string..

*/

#include<bits/stdc++.h>
using namespace std;

int main()
{
    string s;
    vector<string>vs;
    int tc=0;

    while(getline(cin,s))
    {


        if(s.empty())break;
        //cout << s << "\n";
        vs.clear();
        int n, i,j;
        cin >> n;

        while(n--)
        {
            cin >> i >> j;

            int mn = min(i,j) , mx=max(i,j);
            char ch = s[mn];
            bool f=false;

            for(int i=mn+1; i<=mx; i++)
            {
                if(ch != s[i])
                {
                    f=true;
                    break;
                }

                ch = s[i];
            }

            if(f)
            {
                vs.push_back("No");
            }

            else
            {
                vs.push_back("Yes");
            }
        }

        int len=vs.size();

        cout << "Case " << ++tc << ":\n";

        for(int i=0;i<len;i++)
        {
            cout << vs[i] << "\n";
        }

        cin.ignore();

        s.clear();
    }

    return 0;
}

Comments

Popular posts from this blog

SPOJ-CMG - Collecting Mango

LightOJ 1009 - Back to Underworld

LeetCode Palindrome Number