【白书之路】 1585 - Score 统计分数

1585 - Score

There is an objective test result such as ``OOXXOXXOOO". An `O' means a correct answer of a problem and an `X' means a wrong answer. The score of each problem of this test is calculated by itself and its just previous consecutive `O's only when the answer is correct. For example, the score of the 10th problem is 3 that is obtained by itself and its two previous consecutive `O's.

Therefore, the score of ``OOXXOXXOOO" is 10 which is calculated by ``1+2+0+0+1+0+0+1+2+3".

You are to write a program calculating the scores of test results.


Input


Your program is to read from standard input. The input consists of T test cases. The number of test cases Tis given in the first line of the input. Each test case starts with a line containing a string composed by `O' and `X' and the length of the string is more than 0 and less than 80. There is no spaces between `O' and `X'.

Output


Your program is to write to standard output. Print exactly one line for each test case. The line is to contain the score of the test case.

The following shows sample input and output for five test cases.

Sample Input


5 
OOXXOXXOOO 
OOXXOOXXOO 
OXOXOXOXOXOXOX 
OOOOOOOOOO 
OOOOXOOOOXOOOOX

Sample Input


10 
9 
7 
55 
30

计算一个字符串的额分数,使用以下方法计算每一个字符的分数:

    1.如果当前字符是‘O',那么加一分,并且进行步骤二,如果为'X',分数为0

    2.从当前位置向前查找连续的字符,有几个连续的'O',就加几分

最后,将所有字符的分数相加就是这个字符串的分数


#include <iostream>
#include <stdio.h>
#include <string.h>
#define MAX 100
using namespace std;

char str[MAX];
int len;
int get_score()
{
    int score=0;
    int i,j;
    for(i=0;i<len;i++)
    {
        if(str[i]=='O')//如果当前字符是O
        {
            j=i;
            while(j>=0&&str[j]=='O')//向前查找
            {
                score++;
                j--;
            }
        }
    }
    return score;
}


int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%s",str);
        len=strlen(str);
        printf("%d\n",get_score());
    }
    return 0;
}






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值