There is an objective test result such as “OOXXOXXOOO”. An ‘O’ means a correct answer of a problem and an ‘A’ means a wrong answer. The score of each problem of this test is calculated by itself and its just previous consecutive 'O’s only when the answer is correct. For example, the score of the 10th problem is 3 that is obtained by itself and its two previous consecutive 'O’s.
Therefore, the score of “OOXXOXXOOO” is 10 which is calculated by “1+2+0+0+1+0+0+1+2+3”.
You are to write a program calculating the scores of text results.
#include <iostream>
#include <string.h>
using namespace std;
int main() {
int T;
char a[100];
cin >> T;
while (T--) {
cin >> a;
int n = strlen(a),num=0,score=0;
for (int i = 0; i < n; i++) {
if (a[i] == 'O') {
num++;
score += num;
}
else if (a[i] == 'X')
num = 0;
}
cout << score << endl;
}
}