Created
November 30, 2019 08:15
-
-
Save crazydiver/84d1ffcff1ba8e0887704e1b4dc9f42c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <string> | |
#include <algorithm> | |
#include <cmath> | |
#include <fstream> | |
#include <climits> | |
using namespace std; | |
// The white kitten had had nothing to do with it | |
typedef unsigned long long ull; | |
typedef long long ll; | |
typedef vector<int> vi; | |
typedef vector<ll> vll; | |
typedef vector<vi> vvi; | |
#define MOD 1000000007 | |
#define N 200005 | |
#define pb push_back | |
#define watch(x) cout << (#x) << " is " << (x) << endl | |
#define all(x) (x).begin(), (x).end() | |
#define ang2rad(x) 180/3.14*x | |
const string ALP = "abcdefghijklmnopqrstuvwxyz"; | |
const string ALPB = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | |
ostream &operator<<(ostream &out, vector<int> &v) { | |
for (int el: v) | |
out << el << ' '; | |
return out; | |
} | |
string inp; | |
int sumup = 0; | |
int count_1_in_substr(string); | |
string dec2bin(int); | |
void substr(int); | |
bool do_sub(string); | |
int main() { | |
cin >> inp; | |
for (int i = 0; i < inp.length(); i += 2) { | |
substr(i); | |
} | |
cout << sumup; | |
return 0; | |
} | |
void substr(int strt) { | |
string sub; | |
for (int i = strt; i < inp.length(); ++i) { | |
if (i % 3 == 0) { | |
sub = inp.substr(strt, inp.length() - i); | |
if (do_sub(sub)) ++sumup; | |
} | |
} | |
// return sub; | |
} | |
bool do_sub(string sst) { | |
return (count_1_in_substr(sst) % 2 == 1) ? true : false; | |
} | |
int count_1_in_substr(string str) { | |
int sum = 0; | |
for (int i = 0; i < str.length(); ++i) { | |
sum += (int) str[i]; | |
} | |
string bins = dec2bin(sum); | |
int temp = 0; | |
while (bins != "") { | |
char lsym = bins[bins.length() - 1]; | |
bins.pop_back(); | |
temp += (lsym == '1') ? 1 : 0; | |
} | |
return temp; | |
} | |
string dec2bin(int dec) { | |
string bin = ""; | |
int maxbin = 1; | |
for (; maxbin < dec; maxbin *= 2) {} | |
for (int i = (maxbin - 1) / 2; i >= 0; --i) | |
bin += ((1 << i) & dec) ? '1' : '0'; | |
bin = bin.substr(bin.find('1'), bin.length() - bin.find('1')); | |
return bin; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment