UVa1585

題目:
https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=448&page=show_problem&problem=4460

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
int t;
cin >> t;
string s;
while(t--){
cin >> s;
int total = 0;
vector<int> v(s.size());
if(s[0] == 'O') v[0] = 1;
else v[0] = 0;
for(int i=1; i<(int)s.size(); ++i){
if(s[i] == 'O'){
v[i] = v[i-1] + 1;
}
else v[i] = 0;
}

for(int i=0; i<(int)v.size(); ++i){
total += v[i];
}

cout << total << '\n';
}
return 0;
}