算法竞赛入门经典(第2版)习题3-1 得分 Score UVa1585


这题是开胃小菜,顺利做出。

#include
#include

char s[85];

int main()
{
	int T, tot, cnj;
	scanf("%d", &T);
	while(T--)
	{
		memset(s, 0, sizeof(s));
		scanf("%s", s);
		tot = 0; cnj = 0;
		for(int i = 0; i < sizeof(s); i++)
		{
			if( s[i] == 'O')
			{
				cnj++;
				tot += cnj;
			}
			else cnj = 0;
			//printf("i= %d tot= %d cnj= %d \n", i, tot, cnj);
		}
		printf("%d\n", tot);
	}
	return 0;
}

你可能感兴趣的:(算法竞赛入门经典(第2版))