Score UVA - 1585
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 T is 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.
Sample Input
5
OOXXOXXOOO
OOXXOOXXOO
OXOXOXOXOXOXOX
OOOOOOOOOO
OOOOXOOOOXOOOOX
Sample Output
10
9
7
55
30
HINT
简单的分数统计,不多解释,看代码就好。
Accepted
#include<stdio.h>
#include<string.h>
int main()
{
int sum;
scanf("%d", &sum);
while (sum--)
{
char s[81];
scanf("%s", s);
int len = strlen(s);
int score = 0, t = 0;
for (int i = 0;i < len;i++)
{
if (s[i] == 'O')score += ++t;
else t = 0;
}
printf("%d\n", score);
}
}
最新文章
- 阮一峰对js的见解(10大缺陷)
- (十三)Packet socket 和 sockaddr_ll
- 在 Typescript 2.0 中使用 @types 类型定义
- 临床试验中PI、CI、SI、COI是指哪些人?
- c++模板库(简介)
- redis实现与分析
- html5新增标签兼容性
- CFileDialog的使用方法简单介绍
- javax.Swing 使用GridBagLayout的程序栗子
- Inno Setup 安装inf文件的一个例子
- Java-8ATM
- 用户输入与while循环
- Kafka水位(high watermark)与leader epoch的讨论
- 从头编写 asp.net core 2.0 web api 基础框架 (1)
- Injection of autowired dependencies failed
- ccd采集
- 使用Genymotion遇到的坑_Genymotion无法启动_unable to start the virtual device
- 用liferay实现的增删改查例子-book管理系统
- SQL群集多实例卸载、安装
- 推荐一个lamp的一键安装包