本文版权归点A点C和博客园共有,欢迎转载,但必须保留此段声明,并给出原文连接,谢谢合作!!!

Codeforces Beta Round #77 (Div. 2 Only)-A. Football

 

time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard 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.

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.

Output

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

Sample test(s)
input
001001
output
NO
input
1000000001
output
YES

 分析:只需要判断是否有7个相连的‘0’或者7个相连的‘1’;一旦出现上述情况就跳出,直接输出YES,如果知道查找结束都没出翔就输出NO。

View Code
 1 #include <iostream>
 2 #include<stdio.h>
 3 #include<string.h>
 4 using namespace std;
 5 
 6 char team[105];
 7 
 8 int main()
 9 {
10    int i,num1,num2;
11    while(scanf("%s",team)!=EOF)
12    {
13        num1=0;
14        num2=0;
15        getchar();
16        int n=strlen(team);
17        for(i=0;i<n;i++)
18        {
19            if(team[i]=='0')
20            {
21                num1++;
22                num2=0;
23            }
24            else if(team[i]=='1')
25            {
26                num2++;
27                num1=0;
28            }
29            if(num2>=7||num1>=7)
30            break;
31        }
32        if(i==n)
33        printf("NO\n");
34        else printf("YES\n");
35    }
36     return 0;
37 }

 

posted on 2013-04-20 17:24  点A点C  阅读(452)  评论(0编辑  收藏  举报

导航