Hackerearth: Little Jhool and psychic powers

code:

#include<bits/stdc++.h>
using namespace std;
int main()
{

    int zz,oo;
    string S;
    string z="000000";
    string o="111111";
    cin>>S;
    zz=S.find(z);
    oo=S.find(o);
    if(zz>=0||oo>=0)
    {
        cout<<"Sorry, sorry!"<<endl;
    }
    else
    {
        cout<<"Good luck!"<<endl;
    }
    return 0;
}

another solution of mine:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int len=0,flag=0,i;
    string s;
    cin>>s;
    for(i=0; s[i]!='\0'; i++)
    {
        len++;
    }
    if(len>=6)
    {

        for(int i=0; i<len; i++)
        {
            if(s[i]=='1'&&s[i+1]=='1'&&s[i+2]=='1'&&s[i+3]=='1'&&s[i+4]=='1'&&s[i+5]=='1')
            {
                flag=1;
                break;
            }
            if(s[i]=='0'&&s[i+1]=='0'&&s[i+2]=='0'&&s[i+3]=='0'&&s[i+4]=='0'&&s[i+5]=='0')
            {
                flag=1;
                break;
            }
        }
    }
    if(flag==1)
    {
        cout<<"Sorry, sorry!";
    }
    else
    {
        cout<<"Good luck!";
    }
    return 0;
}

 

 

It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

Your email address will not be published.