23.11.21

题目:

image

代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
using namespace std;
int main(){
int x;
cin>>x;
while(x--){
string s;
cin>>s;
s=s+"0";
int n = s.size();
int x=0;//1.默认开头就是8
int sum=0;
for(int i = 0;i<n;i++){
if(s[i]!='8'){
if(i-x==2){//3.判断长度,开头是8,结尾不是8,两下标相减.
sum++;
}
//2.如果开头不是8,就向后移 (导致了要把字符串加长一位)
//直到找到开头是8
x=i+1;
}
}
cout<<sum<<endl;
}
return 0;
}

运行结果:

image