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. react-redux单元测试(基于react-addons-test-utils,mocha)

    今天补上上次新闻客户端欠下的单元测试.新闻客户端github地址:点我,接上篇博客. 本次单元测试用到了单元测试比较流行的测试框架mocha,用到的是expect断言库,和react官方的测试插件:r ...

  2. 使用jquery.pjax实现SPA单页面应用

    前面文章介绍了前端路由简单实现和Pjax入门方面的文章,今天来分享一个单页面应用神器jquery.pjax.js. HTML 我们准备一个加载div#loading,默认隐藏,ajax请求的时候才显示 ...

  3. apply-javascript-internal

    代码如下:喜欢这种封装方式 <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charse ...

  4. cnblogs latex公式

    选项->启用数学公式支持 \begin{equation*} \begin{split} &xxx\\ &xxx\\ \end{split} \end{equation*} (\ ...

  5. 第一节,初识OpenCV3-图像的读、写、显、格式转化等

    之前一直在看深度学习,突然用到了对图像处理的东西,所以过来补充一下OpenCV基础. 就顺便从网上了买了一本OpenCV 3计算机视觉这本书,这本书比较薄,但是目前已经够我用了,在这里就记录一下我的学 ...

  6. TestNg 9. 参数化测试-DataProvider参数化

    首先利用@DataProvider(name = "XXX")的属性,将name的值XXX 传递给 @Test(dataProvider = "XXX") 看以 ...

  7. 快速入门Splay

    \(splay\) :伸展树(\(Splay Tree\)),也叫分裂树,是一种二叉排序树,它能在\(O(log n)\)内完成插入.查找和删除操作.它由\(Daniel Sleator\)和\(Ro ...

  8. RPC简介

    一:为什么会出现RPC呢? 当公司业务量还是很小的时候,所有的程序都放置在一台机器上,程序之间通过函数或者类来调用.1:当公司的业务发展越来越大,业务线越来越多,公司后端人员也越来越多,分布在不同的业 ...

  9. Harbor 使用 Helm 一键安装

    安装 Harbor Harbor 支持多种安装方式,源码目录下面默认有一个安装脚本(make/install.sh),采用 docker-compose 的形式运行 Harbor 各个组件,和前面的课 ...

  10. Visual Studio 2015中设计UML类图

    1.UML简介 Unified Modeling Language (UML)又称统一建模语言或标准建模语言. 简单说就是以图形方式表现模型,根据不同模型进行分类,在UML 2.0中有13种图,以下是 ...