Toyota Programming Contest 2024#11(AtCoder Beginner Contest 379)

A - Cyclic

链接:A - Cyclic

代码:

#include<bits/stdc++.h>
using namespace std;
int main()
{
	string ss;
	cin>>ss;
	cout<<ss[1]<<ss[2]<<ss[0]<<" "<<ss[2]<<ss[0]<<ss[1];

	return 0;
}

B - Strawberries

链接:B - Strawberries

思路:每次更新cnt

代码:

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	int cnt=0;
	int ans=0;
	for(int i=0;i<n;i++){//注意从0开始
		if(s[i]=='O')
			cnt++;
		else
			cnt=0;
		if(cnt>=k) {
			ans++;
			cnt=0;
		}
	}
	cout<<ans<<endl;
	return 0;
}

 

posted @ 2024-11-24 20:20  hanbaodao  阅读(4)  评论(0编辑  收藏  举报