美文网首页
UVa1585 得分 习题3-1

UVa1585 得分 习题3-1

作者: hhallelujah | 来源:发表于2017-01-25 21:37 被阅读0次

3-1 「UVa1585」得分

给出一个由O和X组成的串(长度为1~80),统计得分。每个O得分为目前连续出现的O的个数,X得分为0.例如,OOXXOXOOOX的得分为 1+2+0+0+1+0+0+1+2+3

代码

#include<stdio.h>
#include<string.h>
int main()
{
    int c,T,sum=0,s=0;
    char str[81];
    scanf("%d",&T);
    while(T--){
    scanf("%s",str);
    for(int i=0;i<strlen(str);i++){
        if(str[i]=='O') sum+=++s;
        else s=0;
    }
    printf("%d\n",sum);
    sum=s=0;
    }
    return 0;

相关文章

网友评论

      本文标题:UVa1585 得分 习题3-1

      本文链接:https://www.haomeiwen.com/subject/clcxittx.html