Advertisement
OMEGAHEAD_MonkoX

Untitled

Nov 8th, 2020
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <typeinfo>
  4. #include <vector>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. vector<char> s;
  10.  
  11.  
  12. class Converter
  13. {
  14. private:
  15. vector<int> a;
  16. int b;
  17. public:
  18. Converter(string str, int ch, bool flag)
  19. {
  20. this->b = ch;
  21. for (int i = 0; i < str.length(); i++)
  22. if (flag) this->a.push_back(ctiTrue(str[i])); else this->a.push_back(ctiFalse(str[i]));
  23. }
  24. int ctiTrue(char c) {
  25. if (c >= '0' && c <= '9' && (c - '0') < this->b) return c - '0'; else if (c >= 'A' && c <= 'Z' && (c - 'A') < this->b) return c - 'A' + 10; else return -1;
  26. }
  27. int ctiFalse(char c)
  28. {
  29. if (c >= '0' && c <= '9' && (c - '0') < this->b) return c - '0'; else if (c >= 'a' && c <= 'z' && (c - 'a') < this->b) return c - 'a' + 10; else return -1;
  30. }
  31. char intToCharTrue(int c)
  32. {
  33. if (c >= 0 && c <= 9) return c + '0'; else return c + 'A' - 10;
  34. }
  35. char intToCharFalse(int c)
  36. {
  37. if (c >= 0 && c <= 9) return c + '0'; else return c + 'a' - 10;
  38. }
  39. int GetN(int final)
  40. {
  41. int x = 0;
  42. for (int i = 0; i < this->a.size(); i++)
  43. {
  44. x = x * this->b + this->a[i];
  45. a[i] = x / final;
  46. x = x % final;
  47. }
  48. return x;
  49. }
  50. bool flag2()
  51. {
  52. for (int i = 0; i < this->a.size(); i++)
  53. if (a[i] != 0) return false;
  54. return true;
  55. }
  56. string convert(int final, bool flag) {
  57. vector<int> b;
  58. int size = 0;
  59. do {
  60. b.push_back(this->GetN(final));
  61. size++;
  62. } while (!this->flag2());
  63.  
  64. string answ = "";
  65. for (int i = b.size() - 1; i >= 0; i--)
  66. if (flag) answ += intToCharTrue(b[i]); else answ += intToCharFalse(b[i]);
  67. return answ;
  68. }
  69. };
  70.  
  71. string write(int n, int d, bool flag)
  72. {
  73. string inp = to_string(n);
  74. int ch = 10;
  75. Converter convertt(inp, ch, flag);
  76. return convertt.convert(d, flag);
  77. }
  78.  
  79.  
  80. int main()
  81. {
  82. int D, L, k = 0;
  83. string N;
  84. cin >> D;
  85. cin >> L;
  86. cin >> N;
  87. Converter convertt(N, 16, true);
  88. N = (convertt.convert(8, true));
  89. for (auto i : N)
  90. if (D == (i - '0'))
  91. k++;
  92. cout << k;
  93. //cout << count(N.begin(), N.end(), to_string(D));
  94.  
  95. return 0;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement