[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种表示方法,分别为从某个位置开始顺时针得到,在这 ...
随机推荐
- webpack入门(三)webpack的api
终于到了webpack api这一篇,我都等不及了0.0; webpack is fed a configuration object. Depending on your usage of webp ...
- linux ./configure check your system clock
checking for a BSD-compatible install... /usr/bin/install -cchecking whether build environment is sa ...
- 洛谷P2414 阿狸的打字机
题意:以trie的形式给出n个字符串,每次询问第x个字符串在第y个字符串中出现了几次. 解:总串长是n2级别的,所以不能用什么后缀自动机... [update]可以建triesam但是不知道trie上 ...
- Python三大web框架简单介绍
Django 是重量级框架:它封装的的功能常丰富非常多所以它是重量级,Django的文档最完善.市场占有率最高.招聘职位最多.Django提供全套的解决方案(full-stack framework ...
- RGBColorspace 与 GRAYColorspace 图片混合后,生成的视频有点问题
最近有一个用户遇到一个情况: 有3张图片,其中前两张是 RGBColorspace,最后一张是 GrayColorspace: 生成的视频,在显示最后一张图片的时候,明显出现奇怪的色彩区域,看下图: ...
- 自制模态窗体闪烁效果: MessageBeep & FlashWindowEx
SetFocus(hwnd_frame_preview); //设置焦点 /** 模拟模态窗口动作 **/ MessageBeep(0xFFFFFFFF); //0xFFFFFFFF SystemDe ...
- MongoDB 学习记录(二)yum安装
前言:接着上篇继续学习MongoDB,这次学习的是在Linux下安装MongoDB 环境:centos7.3 安装版本:MongoDB4.0 官网安装教程地址 https://docs.mongodb ...
- 第十四节,卷积神经网络之经典网络Inception(四)
一 1x1卷积 在架构内容设计方面,其中一个比较有帮助的想法是使用 1×1 卷积.也许你会好奇,1×1 的卷积能做什么呢?不就是乘以数字么?听上去挺好笑的,结果并非如此,我们来具体看看. 过滤器为 1 ...
- java eclipse 安卓环境配置
adt下载地址 http://www.runoob.com/w3cnote/android-tutorial-eclipse-adt-sdk-app.html 我的云 安卓学习 java htt ...
- Python3的第一个程序
软件:Anaconda Navigator集成开发环境中的Spyder,自带Python,无需单独安装. 注意:Python对缩进和空格敏感,代码必须对齐(包括注释),否则出现错误unexpected ...