[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种表示方法,分别为从某个位置开始顺时针得到,在这 ...
随机推荐
- Spring Data JPA Batch Insertion
转自:https://www.jeejava.com/spring-data-jpa-batch-insertion/ Spring Data JPA Batch Insertion will sho ...
- A1034. Head of a Gang
One way that the police finds the head of a gang is to check people's phone calls. If there is a pho ...
- [bzoj1692][队列变换]
题目链接 思路 首先肯定想到贪心,从队尾和队首取更小的那个. 但是如果遇到队尾和队首一样大的情况呢,总不能再挨个往前比较.所以就把整个字符串倒过来再挂到现在字符串的后面,也就是把当前字符串对称过去.然 ...
- vue使用element-ui 监听使用回车键事件
因为element-ui 对input做了封装,使用@keyup.enter="fn"触发Enter键事件就不会触发,解决:后面追加.native.@keyup.enter.nat ...
- Git学习笔记——搭建远程仓库
有空再把笔记移上来 注意点:git remote add origin不是相对于所有git仓库,只相对于当前git仓库 心得:远程建立裸仓库,意味着我不应该直接操作远程仓库.如果我是管理员,我应该先p ...
- Linux上svn搭建
安装svn yum -y install subversion 2.创建版本库 svnadmin create /home/svn/test 3.配置用户 vim /home/svn/test/co ...
- Vue(基础七)_webpack打包工具用法(上)
一.前言 1.webpack原理 二.主要内容 1.webpack原理: (1)官网图:我们的项目有多个js, css文件的时候还需要考虑先引入哪一个后引入哪一个,因为这些js文件是相互依赖的,web ...
- display详解
css中的display属性 display属性是我们在前端开发中常常使用的一个属性,其中,最常见的有: none block inline inline-block inherit 下面,我将按照顺 ...
- Error[Pe020]: identifier "FILE" is undefined
Error[Pe020]: identifier "FILE" is undefined 需要添加头文件:#include <stdio.h>
- mysqldump常用备份参数
#!/bin/sh DUMP=/usr/bin/mysqldump OUT_DIR=/var/ftp/iips/mysqlbak LINUX_USER=root DB_NAME=yfdmbd DB_U ...