【白书之路】 1585 - Score 统计分数
2015-09-04 15:29
429 查看
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 testis 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 firstline 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;
}
相关文章推荐
- lucene4下用MultiFieldQueryParser同时搜索多个field时,结果的score浅析
- 【白书之路】 分数化小数 高精度小数运算
- 【白书之路】 排列 permutationy
- 【白书之路】 UVA272 Tex Quates
- 【白书之路】10082 - WERTYU string使用
- 【白书之路】401 - Palindromes 回文串 镜像串
- 【白书之路】340 - Master-Mind Hints 数字统计
- 【白书之路】1583 - Digit Generator
- 【白书之路】1584 - Circular Sequence 最小字典序
- solrj 对solr 的操作
- Lucene/solr的评分公式
- lucene源代码学习之 lucene的经典打分过程 推荐
- function_score 之script_score
- javascript给成绩分等级
- elasticsearch java原生打分插件开发
- elasticsearch排序(相关性排序score)
- Solr进阶之Solr综合文本相似度的多因素权重排序实现
- 【白书之路】 Uva 1587 Box 六个面是否能组成长方体
- 【白书之路】 10340 All in All 判断子串
- 【白书之路】UVa 202 Repeating Decimals 计算小数循环节