[C++]3-1 得分(Score ACM-ICPC Seoul 2005,UVa1585)
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
OOOOXOOOOXOOOOXSample 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)的更多相关文章
- 得分(Score, ACM/ICPC Seoul 2005,UVa 1585)
#include<cstdio>#include<cstdlib>#include<cstring>int main(){ char s[80];//输入OOXXO ...
- 得分(Score,ACM/ICPC Seoul 2005,UVa 1585)
#include<stdio.h> int main(void) { char b; int t,cou,sum; scanf("%d",&t); getcha ...
- UVa 1585 - Score - ACM/ICPC Seoul 2005 解题报告 - C语言
1.题目大意 给出一个由O和X组成的字符串(长度为80以内),每个O的得分为目前连续出现的O的数量,X得分为0,统计得分. 2.思路 实在说不出了,这题没过脑AC的.直接贴代码吧.=_= 3.代码 # ...
- [C++]最小生成元 (Digit Generator, ACM/ICPC Seoul 2005, UVa1583)
Question 例题3-5 最小生成元 (Digit Generator, ACM/ICPC Seoul 2005, UVa1583) 如果x+x的各个数字之和得到y,就是说x是y的生成元.给出n( ...
- 分子量 (Molar Mass,ACM/ICPC Seoul 2005,UVa1586)
习题 3-3 分子量 (Molar Mass,ACM/ICPC Seoul 2005,UVa1586) 给出一种物质的分子式(不带括号),求分子量.本题中的分子式只包含4种原子,分别为C,H,O,N, ...
- 生成元(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 ...
- 生成元(Digit Generator,ACM/ICPC Seoul 2005,UVa 1583)
#include<cstdio>#include<cstdlib>#include<cstring>using namespace std;int t, n, a, ...
- 生成元(Digit Generator, ACM/ICPC Seoul 2005, UVa1583)
如果x加上x的各个数字之和得到y,就说x是y的生成元.给出n(1≤n≤100000),求最小 生成元.无解输出0.例如,n=216,121,2005时的解分别为198,0,1979. [分析] 本题看 ...
- [C++]环状序列(CircularSequence,ACM/ICPC Seoul 2004,UVa1584)
Question 例题3-5 环状序列(CircularSequence,ACM/ICPC Seoul 2004,UVa1584) 长度为n的环状串有n种表示方法,分别为从某个位置开始顺时针得到,在这 ...
随机推荐
- A1133. Splitting A Linked List
Given a singly linked list, you are supposed to rearrange its elements so that all the negative valu ...
- FindExecutable:查找与一个指定文件关联在一起的程序的文件名
百度百科:http://baike.baidu.com/view/1285880.htm ------------------------------------------------------- ...
- 一文看懂npm、yarn、pnpm之间的区别
文作者对比了当前主流的包管理工具npm.yarn.pnpm之间的区别,并提出了合适的使用建议,以下为译文: NPM npm是Node.js能够如此成功的主要原因之一.npm团队做了很多的工作,以确保n ...
- [转]深入理解CSS中的层叠上下文和层叠顺序
http://www.zhangxinxu.com/wordpress/2016/01/understand-css-stacking-context-order-z-index/ 零.世间的道理都是 ...
- pytest 7 assert断言
前言:断言是自动化最终的目的,一个用例没有断言,就失去了自动化测试的意义了. 断言用到的是 assert关键字.之前的介绍,有的测试方法中其实用到了assert断言.简单的来说,就是预期的结果去和实际 ...
- vue(基础一)_基本指令的使用
一.前言 1.基本骨架 2.插值表达式{{ }} 3.vue起的作用,在开发中充当的角色MVC ...
- redis命令参考和redis文档中文翻译版
找到了一份redis的中文翻译文档,觉得适合学习和查阅.这份文档翻译的真的很良心啊,他是<Redis 设计与实现>一书的作者黄健宏翻译的. 地址:http://redisdoc.com/i ...
- vbox的桥接网络
直接连接到了外网上,宿主机可以访问虚拟机,但是虚拟机不可以访问宿主机.缺点:宿主机没有网络时,将不能ping通. 宿主机:win10 网络:无线 虚拟机系统:centos6.5 vbox版本:6.0. ...
- python3 aes加解密
# encoding: utf-8 import xlrd import os import yaml import logging.config from Crypto.Cipher import ...
- REST_返回形式
摘录: "Web resources" were first defined on the World Wide Web as documents or files identif ...