Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <typeinfo>
- #include <vector>
- #include <algorithm>
- using namespace std;
- vector<char> s;
- class Converter
- {
- private:
- vector<int> a;
- int b;
- public:
- Converter(string str, int ch, bool flag)
- {
- this->b = ch;
- for (int i = 0; i < str.length(); i++)
- if (flag) this->a.push_back(ctiTrue(str[i])); else this->a.push_back(ctiFalse(str[i]));
- }
- int ctiTrue(char c) {
- 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;
- }
- int ctiFalse(char c)
- {
- 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;
- }
- char intToCharTrue(int c)
- {
- if (c >= 0 && c <= 9) return c + '0'; else return c + 'A' - 10;
- }
- char intToCharFalse(int c)
- {
- if (c >= 0 && c <= 9) return c + '0'; else return c + 'a' - 10;
- }
- int GetN(int final)
- {
- int x = 0;
- for (int i = 0; i < this->a.size(); i++)
- {
- x = x * this->b + this->a[i];
- a[i] = x / final;
- x = x % final;
- }
- return x;
- }
- bool flag2()
- {
- for (int i = 0; i < this->a.size(); i++)
- if (a[i] != 0) return false;
- return true;
- }
- string convert(int final, bool flag) {
- vector<int> b;
- int size = 0;
- do {
- b.push_back(this->GetN(final));
- size++;
- } while (!this->flag2());
- string answ = "";
- for (int i = b.size() - 1; i >= 0; i--)
- if (flag) answ += intToCharTrue(b[i]); else answ += intToCharFalse(b[i]);
- return answ;
- }
- };
- string write(int n, int d, bool flag)
- {
- string inp = to_string(n);
- int ch = 10;
- Converter convertt(inp, ch, flag);
- return convertt.convert(d, flag);
- }
- int main()
- {
- int D, L, k = 0;
- string N;
- cin >> D;
- cin >> L;
- cin >> N;
- Converter convertt(N, 16, true);
- N = (convertt.convert(8, true));
- for (auto i : N)
- if (D == (i - '0'))
- k++;
- cout << k;
- //cout << count(N.begin(), N.end(), to_string(D));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement