Problem
https://www.hackerearth.com/practice/basic-programming/implementation/basics-of-implementation/practice-problems/algorithm/psychic-powers/
Solution
https://www.hackerearth.com/practice/basic-programming/implementation/basics-of-implementation/practice-problems/algorithm/psychic-powers/
Solution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
As soon as you click on the link below, which is reserved entirely for you, many things will finally change in your life.
ReplyDeleteThis 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