Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <string>
- #include <sstream>
- #include <algorithm>
- #include <vector>
- #include <stdlib.h>
- #include <stdio.h>
- #include <fstream>
- #include <stack>
- #include <map>
- #include <cstring>
- #include <cmath>
- #include <set>
- #include <iterator>
- #include <cmath>
- #include <locale>
- using namespace std;
- string ToBinary(char c)
- {
- static int mask[] = { 1, 2, 4, 8, 16, 32, 64, 128 };
- string result;
- int i = 8;
- while( i-- )
- {
- result += (c & mask[i]) ? '1' : '0';
- }
- return result;
- }
- //The white kitten had had nothing to do with it
- string sum(const string s1, const string s2) {
- int len1 = s1.size(), len2 = s2.size(), bit1, bit2;
- string ls1 = len1<len2 ? s1 : s2, ls2 = len1<len2 ? s2 : s1, result;
- for (int i = ls1.size(); i < ls2.size(); ++i) ls1 = '0' + ls1;
- int carry = 0;
- for (int i = ls2.size() - 1; i >= 0; --i) {
- bit1 = ls1.at(i) - '0';
- bit2 = ls2.at(i) - '0';
- char sum = (bit1 ^ bit2 ^ carry) + '0';
- result = sum + result;
- carry = (bit1&carry)|(bit2&carry)|(bit1&bit2);
- }
- if (carry) result = '1' + result;
- return result;
- }
- int main() {
- int answ = 0, kol = 0;
- string str2, str3, str4 = "";
- getline(cin, str2);
- for (auto i = 0; i < str2.size(); i += 2){
- for (auto j = 1; j <= str2.size() - i ; ++j)
- {
- if ((i + j - 1) % 3 == 0){
- kol = 0;
- str3 = str2.substr(i, j);
- for(auto el:str3)
- {
- ++kol;
- if (kol == 1)
- str4 = ToBinary(el);
- else
- str4 = sum(str4, ToBinary(el));
- }
- if (count(str4.begin(), str4.end(), '1') % 2 != 0 )
- answ += 1;
- }
- }
- }
- cout << answ;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement