博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【UVA】 1585 --- Score
阅读量:2039 次
发布时间:2019-04-28

本文共 1898 字,大约阅读时间需要 6 分钟。

【UVA】 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 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

题意:

如何计算你们的得分呢?,如“OOXXOXXOOO”。 “O”表示问题的正确答案,“X”表示错误的答案。那么它得分是由它自己和它刚刚以前连续的’O’只有当答案是正确的。
例如,第10个问题的分数是由其自身和它的两个先前连续的“0”获得的3。

因此,“OOXXOXXOOO”的得分是通过“1 + 2 + 0 + 0 + 1 + 0 + 0 + 1 + 2 + 3”计算的10。你要编写一个计算测试结果分数的程序。

输入
输入第一行一个整数T,表示由T个测试用例组成。

每个测试用例以包含由’O’和’X’组成的字符串的行开始,并且字符串的长度大于0且小于80.在’O’和’X’之间没有空格。

输出
每个测试用例输出一行。该行是包含测试用例的分数。
样例输出
5
OOXXOXXOOO
OOXXOOXXOO
OXOXOXOXOXOXOX
OOOOOOOOOO
OOOOXOOOOXOOOOX

样例输出

10
9
7
55
30

#include 
#include
using namespace std;int main() {
int t; cin >> t; while (t--) {
char arr[81]; cin >> arr; int len = strlen(arr); int x = 1, sum = 0; for (int i = 0; i < len; i++) {
if (arr[i] == 'O') {
sum += x; x++; } else {
x = 1; } } cout << sum << endl; } return 0;}

转载地址:http://rgyof.baihongyu.com/

你可能感兴趣的文章
VS的路径变量[转]
查看>>
MFC消息处理[转]
查看>>
cookie被禁止后怎样使用session的解决方案
查看>>
Eclipse 部分快捷键失效解决
查看>>
Bootstrap 自定义弹框
查看>>
MyBatis 分页插件 PageHelper 使用方法
查看>>
AbstractQueuedSynchronizer 源码分析
查看>>
分布式以客户为中心的一致性
查看>>
java 注解
查看>>
CAS:乐观锁实现
查看>>
压力测试工具Apache ab
查看>>
Linux - Shell
查看>>
怎样成为优秀的软件模型设计者?
查看>>
解决spring和struts配合问题
查看>>
嵌入式系统Linux内核开发工程师必须掌握的三十道题
查看>>
产品管理系列(一)---优秀的产品经理所具有的素质
查看>>
架构师之路(5)---IoC框架
查看>>
ExtJS 实现的Web文件管理系统
查看>>
SOA架构师注意的问题
查看>>
最佳拍档:首席市场官与首席技术官
查看>>