The score of 'O' and 'X'

题目描述

注意要点:

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

代码实现

include

include <stdio.h>

include <stdlib.h>

include

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
_for(i,0,sz){
if(buf[i]=='O')
sum+=(++cnt);//sum是累加的,cnt遇到字符X会清0
else cnt = 0;
}
printf("%d\n",sum);
}
return 0;
}

posted @ 2018-11-26 19:18  芷恬  阅读(189)  评论(0)    收藏  举报