Question

习题3-1 得分(Score ACM-ICPC Seoul 2005,UVa1585)

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

Description
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 ofOOXXOXXOOO” 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.
The following shows sample input and output for five test cases.

Sample Input
5
OOXXOXXOOO
OOXXOOXXOO
OXOXOXOXOXOXOX
OOOOOOOOOO
OOOOXOOOOXOOOOX

Sample Output
10
9
7
55
30

Think

  简单题。略。

Code

/*
习题3-1 得分(Score ACM-ICPC Seoul 2005,UVa1585) 题目:给出一个由O和X组成的串(长度为1~80),统计得分。
每个O的分数为目前连续出现的O的个数,X的得分为0。
例如:OOXXOXXOOO的得分为1+2+0+0+1+0+0+1+2+3。
*/
#include<iostream>
#include<string.h>
using namespace std; const int maxn = 85;
char str[maxn]; int main(){
int n,sum;
int prev;//记录前面累加的和
scanf("%d", &n);
while(n--){
scanf("%s", &str);
sum = prev = 0;//默认累计为0
for(int i=0,len = strlen(str);i<len;i++){
if(str[i] == 'O'){
prev++;
sum += prev;
} else {
prev = 0;
}
}
printf("%d\n", sum);
}
return 0;
}

  

[C++]3-1 得分(Score ACM-ICPC Seoul 2005,UVa1585)的更多相关文章

  1. 得分(Score, ACM/ICPC Seoul 2005,UVa 1585)

    #include<cstdio>#include<cstdlib>#include<cstring>int main(){ char s[80];//输入OOXXO ...

  2. 得分(Score,ACM/ICPC Seoul 2005,UVa 1585)

    #include<stdio.h> int main(void) { char b; int t,cou,sum; scanf("%d",&t); getcha ...

  3. UVa 1585 - Score - ACM/ICPC Seoul 2005 解题报告 - C语言

    1.题目大意 给出一个由O和X组成的字符串(长度为80以内),每个O的得分为目前连续出现的O的数量,X得分为0,统计得分. 2.思路 实在说不出了,这题没过脑AC的.直接贴代码吧.=_= 3.代码 # ...

  4. [C++]最小生成元 (Digit Generator, ACM/ICPC Seoul 2005, UVa1583)

    Question 例题3-5 最小生成元 (Digit Generator, ACM/ICPC Seoul 2005, UVa1583) 如果x+x的各个数字之和得到y,就是说x是y的生成元.给出n( ...

  5. 分子量 (Molar Mass,ACM/ICPC Seoul 2005,UVa1586)

    习题 3-3 分子量 (Molar Mass,ACM/ICPC Seoul 2005,UVa1586) 给出一种物质的分子式(不带括号),求分子量.本题中的分子式只包含4种原子,分别为C,H,O,N, ...

  6. 生成元(Digit Generator ,ACM/ICPC Seoul 2005 ,UVa 1583)

    生成元:如果 x 加上 x 各个数字之和得到y,则说x是y的生成元. n(1<=n<=100000),求最小生成元,无解输出0. 例如:n=216 , 解是:198 198+1+9+8=2 ...

  7. 生成元(Digit Generator,ACM/ICPC Seoul 2005,UVa 1583)

    #include<cstdio>#include<cstdlib>#include<cstring>using namespace std;int t, n, a, ...

  8. 生成元(Digit Generator, ACM/ICPC Seoul 2005, UVa1583)

    如果x加上x的各个数字之和得到y,就说x是y的生成元.给出n(1≤n≤100000),求最小 生成元.无解输出0.例如,n=216,121,2005时的解分别为198,0,1979. [分析] 本题看 ...

  9. [C++]环状序列(CircularSequence,ACM/ICPC Seoul 2004,UVa1584)

    Question 例题3-5 环状序列(CircularSequence,ACM/ICPC Seoul 2004,UVa1584) 长度为n的环状串有n种表示方法,分别为从某个位置开始顺时针得到,在这 ...

随机推荐

  1. 简明的Python教程当中的几个疑惑点分析#1

    #1简明的Python教程中的第11章面向对象编程学习中的类与对象的方法里面 有这么一个案例:使用类与对象的变量 #coding:utf-8 #类与对象的变量学习 class Person: popu ...

  2. (三)flask中的请求钩子函数

    请求勾子 在客户端和服务器交互的过程中,有些准备工作或扫尾工作需要处理,比如: 在请求开始时,建立数据库连接: 在请求开始时,根据需求进行权限校验: 在请求结束时,指定数据的交互格式: 为了让每个视图 ...

  3. A1107. Social Clusters

    When register on a social network, you are always asked to specify your hobbies in order to find som ...

  4. 【CH6802】车的放置

    题目大意:给定一个 N*M 的棋盘,棋盘上有些点不能放置任何东西,现在在棋盘上放置一些车,问最多可以放置多少个车而不会互相攻击. 题解:将放置一个车看作连接一条无向边,因为每一行和每一列之间只能放置一 ...

  5. jmeter自动生成测绘报告并发送邮件

    步骤: 1.安装ant,添加到环境变量(windows是将bin目录添加到path.cmd命令输入 ant -v 查看版本号) (mac:brew install ant ant –version) ...

  6. php将用户信息提交到表单并且以txt文档打印出来

    1.分析: ====不推荐这种======== <?php function foo(){ // global $message; if(empty($_POST['username'])){ ...

  7. Collection 接口

    Collection 接口中的方法 ArrayList implements List List extends Collection 主要方法:toArray(); 集合转数组 clear(); 清 ...

  8. 关键字(6):trigger触发器

    trigger是个特殊的存储过程,它的执行不是由程序调用,也不是手工启动,而是由事件来触发,比如当对一个表进行操作(insert,delete,update)时就会激活它执行.触发器经常用于加强数据的 ...

  9. 关于web-root和web-inf的用处

    web-inf下的页面不能直接反问,必须通过servlet页面进行跳转,安全性高. web-root下的页面能直接通过地址栏来访问,安全性低. 哪些页面放在web-root下,哪些放在web-inf下 ...

  10. BZOJ2006 ST表 + 堆

    https://www.lydsy.com/JudgeOnline/problem.php?id=2006 题意:在长度N的序列中求K段长度在L到R之间的区间,使得他们的和最大 很容易想到要求一个前缀 ...