题目大意是给一个由O和X组成的字符串,而这个字符串的得分是由连续的O的数目来统计的。比如OOXXOOXXOO的得分就是1+2+0+0+1+2+0+0+1+2=9。了解了题目大意就好解决了。

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <ctype.h>
using namespace std ;
 
const int maxn = 100005 ;
 
int main(){
    int t ;
    scanf("%d" , &t) ;
    getchar() ;
    while ( t -- ){
        int tot = 0 ;
        int ans = 0 ;
        char ch ;
        while ( (ch = getchar()) != 'n' ){
            if ( ch == 'O' ) { tot ++ ; ans += tot ; }   ///遇到O则tot先加,再把结果加到ans上
            else tot = 0 ;        ///遇到X将tot清零
        }
        printf("%dn" , ans) ;
    }
    return 0 ;
}

 

内容来源于网络如有侵权请私信删除
你还没有登录,请先登录注册
  • 还没有人评论,欢迎说说您的想法!

相关课程

3674 49元 98元 5折