Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- string toBinary(int n)
- {
- string r;
- while (n != 0)
- {
- r = (n % 2 == 0 ? "0" : "1") + r;
- n /= 2;
- }
- return r;
- }
- int getGrade(string binary)
- {
- int N, contor = 0;
- N = binary.length() + 1;
- for (int i = 0; i < N - 3; ++i)
- {
- string k;
- k = binary.substr(i, 3);
- if (k == "101")
- {
- contor++;
- }
- }
- return contor;
- }
- int main()
- {
- int N;
- cin >> N;
- int contor = 0;
- string inBinary = toBinary(N);
- cout << inBinary << endl;
- cout << getGrade(inBinary);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement