Bookmark and Share

free counters
Back to the Training Home

Lesson: 32
Problem: 2501
Title: Gauß in Elementary School
Difficulty Level: 2.0
Date: MAR 02, 2009
Site: http://acm.tju.edu.cn/toj/showp2501.html

Another easy problem. Carefully observe my code if you are very beginner.

#include<stdio.h>

char input[100];

int getResult() {
	int sum = 0, i, pre = 0;
	for(i = 0; input[i]; i++) {
		if(input[i] == 'X')  {
			pre = 0;
			continue;
		}
		if(input[i] == 'O') {
			pre++;
			sum += pre;
		}
	}
	return sum;
}

int main() {
	int n;
	scanf("%d",&n);
	while(n--) {
		scanf("%s",input);
		printf("%d\n",getResult());
	}
	return 0;
}
Back to the Training Home