-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathB.cpp
54 lines (49 loc) · 812 Bytes
/
B.cpp
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mp make_pair
#define pb push_back
bool comp(ll a, ll b) {
return a>b;
}
void solve(){
// Solve here
string s;
cin>>s;
ll l = s.size();
ll t = 0;
vector<ll> v;
for(ll i=0;i<l;i++) {
if(s[i] == '1'){
t++;
while(s[i]==s[i+1] and s[i] == '1' and i<l) {
i++;
t++;
}
}
if(t>0) v.pb(t);
t = 0;
}
sort(v.begin(), v.end(), comp);
ll ans = 0;
for(int i=0;i<v.size();i+=2) {
ans+=v[i];
}
cout<<ans<<endl;
v.clear();
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios::sync_with_stdio(0);
cout.tie(0);
cin.tie(0);
int t;
cin>>t;
while(t--){
solve();
}
return 0;
}