Game with Telephone Numbers

time limit per test 1 second
memory limit per test 256 megabytes

题目链接http://codeforces.com/problemset/problem/1155/B
B. Game with Telephone Numbers---简单思维--Educational Codeforces Round 63 (Rated for Div. 2)_编程开发
B. Game with Telephone Numbers---简单思维--Educational Codeforces Round 63 (Rated for Div. 2)_编程开发_02


题目大意:给你一串数字让你和一个玩家删数,你先手,直至删到11个为止,如果该11位数字是电话号(开头为8),则输出YES,否则输出NO。。

我们只需要判断第(n-11)/2+1个8的前面有几个非8的数字,如果大于(n-11)/2则NO(也就是说对手已经将前(n-11)/2个8删去了,而第(n-11)/2+1个8的前方还有非8的数字)

以下是AC代码:

#include <bits/stdc++.h>
using namespace std;
const int mac=1e5+10;
char s[mac];
int main()
{
	int n;
	scanf ("%d",&n);
	scanf ("%s",s);
	int tot=0,oth=0;
	for (int i=0; i<n; i++){
		if (s[i]-'0'==8) tot++;
		else oth++;
		if (tot>(n-11)/2) break;
	} 
	if (oth>(n-11)/2) {
		printf ("NO\n");
	}
	else printf ("YES\n");
	return 0;
}