概述
小声BB
前段时间攒下点题,不用刷题的感觉真好
题干
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”.
Examples
Input
001001
Output
NO
Input
1000000001
Output
YES
分析
这道题其实不难,就是连看7个位置是否一致,那比较简单的方法就是循环一遍直接7个判断,我的话这里采用了比较一遍记录个数的方法,省了冗余的比较
代码
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
string s;
int a[105],i,ans = 0;
a[0] = 1;
cin >> s;
for(i = 1;i < s.length();i++)
if(s[i] == s[i - 1])
{
a[i] = a[i - 1] + 1;
if(a[i] == 7)
{
ans = 1;
break;
}
}
else
a[i] = 1;
if(ans)
cout << "YES";
else
cout << "NO";
return 0;
}
最后
以上就是整齐唇膏为你收集整理的Codeforces——96A Football的全部内容,希望文章能够帮你解决Codeforces——96A Football所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复