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;
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法