Codeforces 1167A-Telephone Number

题目链接:http://codeforces.com/problemset/problem/1167/A

思路:检索前面0 ~(n −11)个字符中是否有 8 即可。

AC代码:

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<string>
 4 using namespace std;
 5 int main()
 6 {
 7     int t;
 8     cin >> t;
 9     while(t--)
10     {
11         int n;
12         string a;
13         bool flag = false;
14         cin >> n >> a;
15         for(int i = 0;i <= n - 11;i++)
16         {
17             if(a[i] == '8') flag = true;
18         }
19         if(flag && a.size() >= 11) cout << "YES" << endl;
20         else cout << "NO" << endl;
21     }
22     return 0;
23 }