qq_31481531 2015-11-17 13:33 采纳率: 0%
浏览 1699

c语言入门级问题,代码已写,但不知哪里出错,求各位帮帮我

Description

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 Input
Input

001001

Output

NO

Input

1000000001

Output

YES

#include<stdio.h>
#include<string.h>
int main()
{
    int i,length,count=0;
    char a[105];

    while(scanf("%s",a)!=EOF)
    {
        length=strlen(a);
        for(i=0;i<length;i++)
        {
            if(a[i]==a[i-1])
            {
                count+=1;
            }
            else
            {
                count=count;
            }
        }
        if(count>=7)
        {
            printf("YES\n");
        }
        else
        {
            printf("NO\n");
        }
    }
    return 0;
}

  • 写回答

3条回答 默认 最新

  • ysuwood 2015-11-17 15:54
    关注

    改一下逻辑:

     #include<stdio.h>
    #include<string.h>
    int main()
    {
        int i,length,count=0;
        char a[105];
        while(scanf("%s",a)!=EOF)
        {
            count=0;//初始化
            length=strlen(a);
            for(i=1;i<length;i++) //修改,每一个和前一个比较,就要从i=1开始
            {
                if(a[i]==a[i-1])
                {
                    count+=1;
                }
                else
                {
                    count=0;//修改,不同就重新计数
                }
                if(count>=7)
                {
                    break;
                }
            }
            if(count>=1)
            {
                printf("YES\n");
            }
            else
            {
                printf("NO\n");
            }
        }
        return 0;
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?