UVa 1585 - Score - ACM/ICPC Seoul 2005 解题报告 - C语言

1.题目大意

给出一个由O和X组成的字符串(长度为80以内),每个O的得分为目前连续出现的O的数量,X得分为0,统计得分。

 

2.思路

实在说不出了,这题没过脑AC的。直接贴代码吧。=_=

 

3.代码

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

  

参考书目:算法竞赛入门经典(第2版) 刘汝佳 编著

posted @ 2016-10-11 14:06  rgvb178  阅读(1508)  评论(0编辑  收藏  举报