水题得分...

https://vjudge.net/problem/UVA-1585

题目大概意思是:给出一个由O和X组成的串(长度为1~80),统计得分。每一个O的得分为目前连续出现的O的个数,X的得分为0,例如:OOXXOXXOOO的得分为1+2+0+0+1+0+0+1+2+3.

思路:因为题目是要求连续的O,所以遇到X,就要重新统计O的个数;

代码:

#include<iostream>
#include<string.h>
using namespace std;
char s[81];
int main()
{
	int n;
	cin >> n;
	while (n--)
	{
		int sum = 0;
		cin >> s;
		int temp = 0;
		for (int i = 0; i < strlen(s); i++)
		{
				temp++;
			if (s[i] == 'X')//遇到X,就要从0重新开始;
				temp = 0;
			sum += temp;
		}
		cout << sum << endl;
	}
	return 0;
}


猜你喜欢

转载自blog.csdn.net/weixin_41676901/article/details/80544887