AD1

Friday, 7 July 2017

Little Jhool and psychic powers

Problem

https://www.hackerearth.com/practice/basic-programming/implementation/basics-of-implementation/practice-problems/algorithm/psychic-powers/

Solution


#include <iostream>
#include <cstdlib>
#include <string>
#include <math.h>
using namespace std;
int main(int argc, char** argv) {
string s;
cin>>s;
int i=0;
int sum=0;
int flag=0;
while(s[i]!='\0')// loop all elements
{
for(int j=i;j<=i+5;j++)// check every 6 consecutive numbers
{
sum+=s[j];
}
if(sum==288||sum==294)// if you found 6 consecutive ones or zeros (sum is ascii , because input is string)
{
flag=1;break;
}
i++;// move to next element
sum=0;//reset sum
}
if(flag){cout<<"Sorry, sorry!"<<endl;}
else if(flag==0){cout<<"Good luck!";}
return 0;
}

1 comment:

  1. As soon as you click on the link below, which is reserved entirely for you, many things will finally change in your life.

    This is because you have been chosen to receive your personalized study at no cost. And trust me, you will be surprised by everything you learn.

    Follow this link: => Many things will change in your life

    With my most warm friendship,

    Ashima





    ReplyDelete