Advertisement
OMEGAHEAD_MonkoX

Untitled

Jan 15th, 2020
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string>
  4. #include <sstream>
  5. #include <algorithm>
  6. #include <vector>
  7. #include <stdlib.h>
  8. #include <stdio.h>
  9. #include <fstream>
  10. #include <stack>
  11. #include <map>
  12. #include <cstring>
  13. #include <cmath>
  14. #include <set>
  15. #include <iterator>
  16. #include <cmath>
  17. #include <locale>
  18.  
  19. using namespace std;
  20.  
  21. string ToBinary(char c)
  22. {
  23. static int mask[] = { 1, 2, 4, 8, 16, 32, 64, 128 };
  24. string result;
  25. int i = 8;
  26. while( i-- )
  27. {
  28. result += (c & mask[i]) ? '1' : '0';
  29. }
  30. return result;
  31. }
  32. //The white kitten had had nothing to do with it
  33. string sum(const string s1, const string s2) {
  34. int len1 = s1.size(), len2 = s2.size(), bit1, bit2;
  35. string ls1 = len1<len2 ? s1 : s2, ls2 = len1<len2 ? s2 : s1, result;
  36. for (int i = ls1.size(); i < ls2.size(); ++i) ls1 = '0' + ls1;
  37. int carry = 0;
  38. for (int i = ls2.size() - 1; i >= 0; --i) {
  39. bit1 = ls1.at(i) - '0';
  40. bit2 = ls2.at(i) - '0';
  41. char sum = (bit1 ^ bit2 ^ carry) + '0';
  42. result = sum + result;
  43. carry = (bit1&carry)|(bit2&carry)|(bit1&bit2);
  44. }
  45. if (carry) result = '1' + result;
  46. return result;
  47. }
  48. int main() {
  49. int answ = 0, kol = 0;
  50. string str2, str3, str4 = "";
  51. getline(cin, str2);
  52. for (auto i = 0; i < str2.size(); i += 2){
  53. for (auto j = 1; j <= str2.size() - i ; ++j)
  54. {
  55. if ((i + j - 1) % 3 == 0){
  56. kol = 0;
  57. str3 = str2.substr(i, j);
  58. for(auto el:str3)
  59. {
  60. ++kol;
  61. if (kol == 1)
  62. str4 = ToBinary(el);
  63. else
  64. str4 = sum(str4, ToBinary(el));
  65. }
  66. if (count(str4.begin(), str4.end(), '1') % 2 != 0 )
  67. answ += 1;
  68. }
  69. }
  70. }
  71. cout << answ;
  72. return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement