Computer Science, asked by raheemmohideen786, 10 months ago

Bob loves playing hockey. One day, as he was watching a hockey match, he was writing t players' current positions on a piece of paper. To simplify the situation he depicted it as string consisting of zeros and ones. A zero orresponds to players of one team; a one corresponds to players of another team. If there are at least 7 players of some team standing one after another, then the situation is considered dangerous. For example, the situation 0100110111111101 is dangerous and 1110111011101 is not. You are given the current situation. Determine whether it is dangerous or not. INPUT One Line containing a non-empty string S consisting of characters "0" and "1" OUTPUT ! Print "YES" if the situation is dangerous. Otherwise, print "NO". CONSTRAINTS 1<=length of string <=100 ​

Answers

Answered by Raghav1330
23

Answer:

As no language is specified in the question hence why we're keeping it universal by writing the algorithm and the code snippet of the main logical part of the code fragment.

Explanation:

In the given question we will take a string that will check if it's next six characters are same as that or not.

Hence we will get started with the algorithm

Start

Read string

Store length of string in len as

Len=strlen(string)

Continue step next step until i value exceeds len

Initialise j as i

Continue next 4 steps until j value is i+6

if(string [j]!= string [i])

break;

else

flag=1;

if flag ==1

print as dangerous

End

Code snippet

for(i=0;i<len-1;i++)

{

int j=i;

while(j<=i+6)

{

if(str[j]!=str[i])

break;

else

flag=1;

}

}

if (flag==1)

printf("dangerous");

Answered by poojan
9

Python program to solve Hockey problem.

Language: Python 3.0

Program:

string=input()

if ('1111111' in string) or ('0000000' in string):

   print("YES")

else:

   print("NO")

Test cases:

Testcase1:

Input:

0100110111111101

Output:

YES

Testcase2:

Input:

1110111011101

Output:

NO

Small Trick here: As the question said, the situation is considered as a dangerous one if and one if the string has 7 OR MORE CONTIGUOUS 1s or 0s, we can simply see if the string has 7 continuous 0s or 1s subset or not. Even if there are more than 7, that won't make any change. So, checking for 7 contiguous 1s or 0s is enough.

Learn more:

Write a Python function sumsquare(l) that takes a nonempty list of integers and returns a list [odd,even], where odd is the sum of squares all the odd numbers in l and even is the sum of squares of all the even numbers in l.

brainly.in/question/15473120

Python program to find absolute difference between the odd and even numbers in the inputted number.

brainly.in/question/11611140

Similar questions