zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    CTF---隐写术入门第二题 小苹果
    文件上传
    文件读取
    sqlmap之绕过waf思路
    【小技巧分享】如何通过微博图片进行社工Po主
    Windows 11恢复传统右键菜单-2021.10.5正式版
    sql注入之Oracle注入
    CTF之buuctf
    常见sql注入payload
    信息收集之Github
  • 原文地址:https://www.cnblogs.com/ACshasow/p/3032849.html
Copyright © 2011-2022 走看看