题目描述

注意要点:

  • 使用strlen函数注意加头文件#inlcude <cstring>
  • 循环宏定义for循环#define _for(i,a,b) for(int i=(a);i<(b);++i)

代码实现

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#define _for(i,a,b) for(int i=(a);i<(b);++i) //循环宏定义for循环
using namespace std; int main() {
int T; //测试样例的组数
char buf[128];
scanf("%d\n",&T);
while(T--){
gets(buf);//此处是用gets函数读入
int cnt=0,sum=0,sz=strlen(buf); //在CPP中需要引用#include <cstring>
_for(i,0,sz){
if(buf[i]=='O')
sum+=(++cnt);//sum是累加的,cnt遇到字符X会清0
else cnt = 0;
}
printf("%d\n",sum);
}
return 0;
}

The score of 'O' and 'X'的更多相关文章

  1. Lucene的评分(score)机制研究

    首先,需要学习Lucene的评分计算公式—— 分值计算方式为查询语句q中每个项t与文档d的匹配分值之和,当然还有权重的因素.其中每一项的意思如下表所示: 表3.5 评分公式中的因子 评分因子 描 述 ...

  2. 设有一数据库,包括四个表:学生表(Student)、课程表(Course)、成绩表(Score)以及教师信息表(Teacher)。

    一.            设有一数据库,包括四个表:学生表(Student).课程表(Course).成绩表(Score)以及教师信息表(Teacher).四个表的结构分别如表1-1的表(一)~表( ...

  3. 关于一道数据库例题的解析。为什么σ age>22 (πS_ID,SCORE (SC) ) 选项是错的?

    本人大二学子.近段时间在做数据库复习题的时候遇到一道题,如下. 有关系SC(S_ID,C_ID,AGE,SCORE),查找年龄大于22岁的学生的学号和分数,正确的关系代数表达式是( ) . ⅰ. πS ...

  4. 利用SCORE法则来总结一次偷懒的单元测试过程

    最近遇到一个单元测试的问题,本周正好学个了一个SCORE法则,这里正好练练手应用此法则将问题的前因后果分享给大家. S:背景  代码要有单元测试,检测的标准就是统计代码的单元测试覆盖率,程序员需要达到 ...

  5. Hiho coder 1236 2015 北京网络赛 Score

    五维偏序..一开始被吓到了,后来知道了一种BITSET分块的方法,感觉非常不错. 呆马: #include <iostream> #include <cstdio> #incl ...

  6. Java-集合-第三题 有如下Student 对象, private String name; private int age; private int score; private String classNum; 其中,classNum 表示学生的班号,例如“class05”。 有如下List List list = new ArrayList(); l

    第三题 有如下Student 对象, private String name; private int age; private int score; private String classNum; ...

  7. 第三题 有如下Student 对象, private String name; private int age; private int score; private String classNum; 其中,classNum 表示学生的班号,例如“class05”。 有如下List List list = new ArrayList();

    list.add(new Student("Tom", 18, 100, "class05")); list.add(new Student("Jer ...

  8. Competition-based User Expertise Score Estimation-20160520

    1.Information publication:sigir 2011 author:Jing Liu Harbin Institute of TechnologyMicrosoft Researc ...

  9. linux 终端报错 Out of memory: Kill process[PID] [process name] score问题分析

    从Out of memory来看是内存超出了,后面的 Kill process[PID] [process name] score好像和进程有关了,下面我们就一起来看看linux 终端报错 Out o ...

  10. zoj3819Average Score

    Average Score Time Limit: 2 Seconds      Memory Limit: 65536 KB Bob is a freshman in Marjar Universi ...

随机推荐

  1. Redis只作为缓存,不做持久化的配置

    #1.配置缓存内存限制和清理策略 #作为缓存服务器,如果不加以限制内存的话,就很有可能出现将整台服务器内存都耗光的情况,可以在redis的配置文件里面设置: #example: # 限定最多使用1.5 ...

  2. office excel 2010 破解版下载地址

    office excel 2010 破解版下载地址  http://www.xitongzhijia.net/soft/24189.html

  3. Windows Server 2012 R2 Standard x64 deploy Visual Studio 2015 Application

    When I run the Server application on Windows Server 2012 R2 operation system. I meet the error:MSVCP ...

  4. ECS 游戏架构 理解

    转载自:http://blog.csdn.net/i_dovelemon/article/details/25798677 理解 组件-实体-系统 (ECS \CES)游戏编程模型 - 博客频道   ...

  5. 洛谷 P2850 [USACO06DEC]虫洞Wormholes 判负环

    虫洞(wormhole) FJ 在农场上闲逛时,发现他的农场里有很多虫洞.虫洞是一条特殊的有向路径,当 FJ 从它的一头走到另一头后,他将被传送到过去的某个时刻.FJ 的每个农场包括 N(1<= ...

  6. jquery设置select选中的文本

    <select id="prov">  <option value="1">北京市</option>  <option ...

  7. RedisHelper in C#

    自己写了一个RedisHelper,现贴出来,希望各位大神能够指正和优化. using System; using StackExchange.Redis; using System.Configur ...

  8. TF Boys (TensorFlow Boys ) 养成记(一):TensorFlow 基本操作

    本资料是在Ubuntu14.0.4版本下进行,用来进行图像处理,所以只介绍关于图像处理部分的内容,并且默认TensorFlow已经配置好,如果没有配置好,请参考官方文档配置安装,推荐用pip安装.关于 ...

  9. org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'deptDao_a' defined in class path resource [beansAndHibernate.xml]: Cannot resolve reference to bean 'sessionFact

    Error creating bean with name 'deptDao_a' defined in class path 因为更改了类的名字,所以其setter方法没有更改,需要 private ...

  10. 使用#include消除重复代码

    消除重复代码代码很多种,比如: 1)提炼成函数复用 2)使用宏 3)继承 4)使用闭包(boost::bind.boost::function) 上述是最为常用的,对于C++程序,闭包可能用得相对少一 ...