<男孩女孩>不太会,求教
  • 板块学术版
  • 楼主fang_putao
  • 当前回复3
  • 已保存回复3
  • 发布时间2024/11/22 19:35
  • 上次更新2024/11/22 21:21:14
查看原帖
<男孩女孩>不太会,求教
1387375
fang_putao楼主2024/11/22 19:35

题目戳此,请求指教

#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

2024/11/22 19:35
加载中...