Football
Description
Petya loves football very much. One day, as he was watching a footballmatch, he was writing the players' current positions on a piece of paper. Tosimplify the situation he depicted it as a string consisting of zeroes andones. A zero corresponds to players of one team; a one corresponds to playersof another team. If there are at least 7 players of some team standing oneafter another, then the situation is considered dangerous. For example, thesituation 00100110111111101 is dangerous and 11110111011101 is not. You aregiven the current situation. Determine whether it is dangerous or not.
Input
The first input line contains a non-empty string consisting of characters"0" and "1", which represents players. The length of thestring does not exceed 100 characters. There's at least one player from eachteam present on the field.
Output
Print "YES" if the situation is dangerous. Otherwise, print"NO".
Sample Input
Input
001001
Output
NO
Input
1000000001
Output
YES
题解:
输入一个整数,判断是否有连续7个1或0,。
解题思路:
字符串保存数字,判断。
核心代码
for(int i=0;i<n;i++)
{
if(a[i]=='0')
l++;
if(a[i]!='0'&&l<7)
l=0;
if(a[i]=='1')
k++;
if(a[i]!='1'&&k<7)
k=0;
}