Online Judge【UVa】[1585]Score问题描述 问题分析 用i统计连续O的个数,遇见X则i清零scanf版: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 #include<stdio.h> #include<string.h> int main() { int n,sum,l,t; char s[100]; scanf("%d",&n); while(n--) { scanf("%s",s); l=strlen(s); for(int i=t=sum=0; i<l; i++) { if(s[i]=='X') t=0; else if(s[i]=='O') { sum+=++t; } } printf("%d\n",sum); } return 0; }getchar版: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 #include<stdio.h> int main() { int n,sum,i; char t; scanf("%d\n",&n); while(n--) { i=sum=0; while(t=getchar(),t!='\n') { if(t=='X') i=0; else if(t=='O') { sum+=++i; } } printf("%d\n",sum); } return 0; }话说第一次写的时候不知道为什么写不对然后今天突然迷之直接写出来了题目地址:【UVa】[1585]Score