题目戳此,请求指教
#include<bits/stdc++.h>
using namespace std;
string s;
int by=0,gl=0;
int main(){
cin >> s;
int len=s.size();
for(int i = 0;i <= len;i ++){
if(s[i]=='b'&&s[i+1]=='o'&&s[i+2]=='y'){
by ++;
i += 2;
}
else if(s[i]=='b'&&s[i]=='o'){
by ++;
i ++;
}
else if(s[i]=='b'||s[i]=='o'||s[i]=='y' && i < len-1) by ++;
if(s[i]=='g'&&s[i+1]=='i'&&s[i+2]=='r'&&s[i+3]=='l'){
gl ++;
i += 3;
}
else if(s[i]=='g'&&s[i+1]=='i'&&s[i+2]=='r'){
gl ++;
i += 2;
}
else if(s[i]=='g'&&s[i+1]=='i'){
gl ++;
i ++;
}
else if(s[i]=='g'||s[i]=='i'||s[i]=='r'||s[i]=='l' && i < len-1) gl ++;
}
cout << by << endl << gl;
return 0;
}
22分,情况如下:AC,WA,AC,WA,WA,WA,WA,WA,WA