Advertisement
Saleh127

CF 1398B

Oct 19th, 2020
63
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. int main()
  6. {
  7. ios_base::sync_with_stdio(0);
  8. cin.tie(0);cout.tie(0);
  9.  
  10. test
  11. {
  12. ll c,d,e,f,i,j,k,l;
  13. string a;
  14.  
  15. cin>>a;
  16. vector<ll>x;
  17. c=0;
  18. for(i=0;i<a.size();i++)
  19. {
  20. if(a[i]=='1')
  21. {
  22. c++;
  23. }
  24. else
  25. {
  26. x.push_back(c);
  27. c=0;
  28. }
  29. }
  30. if(c) x.push_back(c);
  31. c=0;
  32. sort(x.begin(),x.end());
  33. for(i=x.size()-1;i>=0;i-=2)
  34. {
  35. c+=x[i];
  36. }
  37. cout<<c<<endl;
  38. }
  39.  
  40.  
  41. return 0;
  42. }
  43.  
Advertisement
RAW Paste Data Copied
Advertisement