天天看点

Uva1585-Score-dp

题目链接https://vjudge.net/problem/UVA-1585

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

模拟。

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

           

继续阅读