Skip to content

Commit 0d07d0f

Browse files
committed
Added 1398B - Substring Removal Game.cpp
1 parent ec8181a commit 0d07d0f

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

1398B - Substring Removal Game.cpp

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
// Code Written By: Vikash Patel
5+
6+
// Codeforces Profile: https://codeforces.com/profile/vikashpatel
7+
8+
int main()
9+
{
10+
int t;
11+
cin>>t;
12+
while(t--)
13+
{
14+
string s;
15+
cin>>s;
16+
s.push_back('0');
17+
int c=0;
18+
vector<int> subOnes;
19+
for(auto i : s)
20+
{
21+
if(i=='1')
22+
{
23+
c++;
24+
}
25+
else
26+
{
27+
subOnes.push_back(c);
28+
c=0;
29+
}
30+
}
31+
sort(subOnes.begin(), subOnes.end(), greater<int>());
32+
int ans=0;
33+
for(int i=0;i<subOnes.size();i++)
34+
{
35+
if(i%2==0)
36+
ans+=subOnes[i];
37+
}
38+
cout<<ans<<endl;
39+
}
40+
}

0 commit comments

Comments
 (0)