Header Ad

HackerEarth Little Jhool and psychic powers problem solution

In this HackerEarth Little Jhool and psychic powers problem solution Little Jhool always wanted to have some psychic powers so that he could show off his skills, and magic to people and impress them. (Especially, his girlfriend Big Jhool!) But, in spite of all his efforts, hard work, dedication, Googling, watching youtube videos he couldn't garner any psychic abilities!

He knew everyone was making fun of him, so to stop all of that - he came up with a smart plan. Anyone who came to him to know about their future, he asked them to write a binary number for him - and then, he smartly told them if the future for that person had good in-store or bad.

The algorithm which Little Jhool follows is, as follows:

If the binary number written by the person has six consecutive 0s or 1s, his future is bad.
Otherwise, he says that their future is good.


HackerEarth Little Jhool and psychic powers problem solution


HackerEarth Little Jhool and psychic powers problem solution.

#include <bits/stdc++.h>

using namespace std;

int main()
{
string s;

cin >> s;

for(int i = 0; i + 6 <= s.size(); i++){

if(s[i] == s[i + 1] && s[i] == s[i + 2] && s[i] == s[i + 3] && s[i] == s[i + 4] && s[i] == s[i + 5]){

cout << "Sorry, sorry!";
return 0;
}
}

cout << "Good luck!";

return 0;
}

Second solution

a = raw_input()
print 'Sorry, sorry!' if '0'*6 in a or '1'*6 in a else 'Good luck!'


Post a Comment

0 Comments