Problem solving with programming: Continuous sequence
Given a sequence of 0 and 1s. Check if contains a continuous sequence of 0/1 of length 7.
For example see some input output combinations
Input Output
------------------------------------------
10001010010011 NO
1000000001100 YES
000111111111110 YES
Your program should accept a sequence of 0, 1s as input and print YES of there is a sequence of 7 0/1s in it or NO if does not contain such a sequence.
Given a sequence of 0 and 1s. Check if contains a continuous sequence of 0/1 of length 7.
For example see some input output combinations
Input Output
------------------------------------------
10001010010011 NO
1000000001100 YES
000111111111110 YES
Your program should accept a sequence of 0, 1s as input and print YES of there is a sequence of 7 0/1s in it or NO if does not contain such a sequence.
Read full article from Problem solving with programming: Continuous sequencebool containsSequence(string input){if( input.size() < 7 ){return false;}else{int i;bool dangerous = false;int ccount = 0;int state = -1; //initial statefor( i = 0; i < input.size(); i++ ){if( input[i] == '0' ){if( state != 0 ) //sequence broken{ccount = 1; //reset countstate = 0; //change the state}else //sequence continuesccount++;}else{if( state != 1 )//sequence broken{ccount = 1;state = 1;}elseccount++;}if( ccount == 7 ) //sequence found{return true;}}return false;}