【题目】一个由O和X组成的串,O的得分为目前连续出现的O的个数,X的得分为0。要求统计得分。
我一开始以为要输出表达式,结果好像不需要?
【代码】
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
const int maxn = 85;
char a[maxn];
int main()
{
int t=0;
char x;
//scanf("%s",a);
while(scanf("%c",&x)==1)
{
a[t++] = x;
}
int n = strlen(a);
// printf("%d
",n);
// printf("%c
",a[n]);
int tot = 0;
int sum = 0;
for (int i = 0; i < n - 1; i++)
{
if (a[i] == 'O') ++tot; //printf("%d", ++tot);
if (a[i] == 'X')
{
tot = 0;
//printf("%d", tot);
}
sum += tot;
}
printf("
%d",sum);
system("pause");
return 0;
}