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

本文介绍了一个简单的程序,用于判断足球比赛中某一方队伍是否有至少7名球员连续站在场上,以此来评估比赛局势是否危险。通过读取输入字符串,程序会检查连续的‘0’或‘1’是否达到7个,并据此输出YES或NO。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

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 }

 

转载于:https://www.cnblogs.com/ACshasow/archive/2013/04/20/3032849.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值