96A. Football

96A. Football

96A. Football

  • time limit per test2 seconds
  • memory limit per test256 megabytes
  • inputstandard input
  • outputstandard output

Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds 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 00100110111111101 is dangerous and 11110111011101 is not. You are given the current situation. Determine whether it is dangerous or not.

佩蒂娅非常喜欢足球。一天,当他在看一场足球比赛时,他正在一张纸上写下球员们目前的位置。为了简化情况,他把它描绘成一个由0和1组成的字符串。零对应于一个队的球员;一个对应另一个队的队员。如果某支球队至少有7名球员一个接一个地站着,那么这种情况就被认为是危险的。例如,情况00100110111111101是危险的,而11110111011101不是。你会看到目前的情况。确定它是否危险。

Input

The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field.

第一个输入行包含一个非空字符串,由代表玩家的字符“0”和“1”组成。字符串的长度不超过100个字符。每个队至少有一名球员在场。

Output

Print "YES" if the situation is dangerous. Otherwise, print "NO".

如果情况危险,请打印“是”。否则,请打印“否”。

Examples
input1

001001

output1

NO

input2

1000000001

output2

YES

Solution
Code
#include <iostream>
using namespace std;
//96A. Football
int main(){
    string s;
    cin>>s;
    int len = s.size();
    int flag = 0;
    if (len<7){
        flag = 1;
        cout << "NO" << endl;
    }
    else{
        for(int i=6;i<len;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] && s[i] == s[i-6]){
                cout <<"YES"<<endl;
                flag = 1;
                break;
            }
        }
    }
    if(flag==0){
        cout<<"NO"<<endl;
    }
}
CodeForces 文章被收录于专栏

https://codeforces.ml/

全部评论

相关推荐

点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务