题目大意:

给出一串由OX组成的序列,求总得分,对于连续的O,每一个都多加一分,如果遇到X,则每个O的分值从1算起,输出总分。

解题思路:

定义一个num,只要没遇到X,num++,ans+=num, 如果遇到X,num的值归零即可。AC代码:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int _max = 1e3;
int main()
{
	int n;
	cin>>n;
	while(n--)
	{
		string s;
		cin>>s;
		int ans=0,t=0;
		for(int i=0;i<s.length();i++)
		{
			if(s[i]=='O')
			{
				t++;
				ans+=t;
			}
			else
			  t=0;
		}
		cout<<ans<<endl;
	}
	return 0;
}

相关文章:

  • 2021-08-15
  • 2021-11-22
  • 2021-07-09
  • 2021-10-09
  • 2021-07-18
  • 2022-12-23
  • 2021-10-24
  • 2021-10-28
猜你喜欢
  • 2022-12-23
  • 2021-05-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-14
  • 2022-02-09
相关资源
相似解决方案