Problem--96A--Codeforces--Football

Football
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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”.

Examples:
input
001001
output
NO
input
1000000001
output
YES

題意:用0代表其中一隊的一個成員,用1代表另一隊的一個成員。當一個球隊至少7個隊員挨在一起時,視爲危險情況,輸出YES;否則輸出NO。所以只需要判斷所輸入的字符串中是否含有“1111111”或者“0000000”即可。

#include<stdio.h>
#include<string.h>
int main()
{
    char player[105];
    scanf("%s",player);
    strstr(player,"0000000")||strstr(player,"1111111")?printf("YES"):printf("NO");
}
發佈了40 篇原創文章 · 獲贊 1 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章