Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <sstream>
- #include <algorithm>
- #include <bitset>
- #include <cmath>
- using namespace std;
- vector<int> input() {
- string s;
- getline(std::cin, s);
- std::vector<int> result;
- std::istringstream iss(s);
- for (string s; iss >> s;) {
- result.push_back(stol(s));
- }
- return(result);
- }
- void print_binary(size_t stringLength, size_t numberOfOnes) {
- unsigned long long int maxNum = pow(2, stringLength);
- unsigned long long int minNum = pow(2, numberOfOnes);
- cout << maxNum << " " << minNum << endl;
- for (unsigned long long int digit = minNum - 1; digit < maxNum; ++digit) {
- std::bitset<100> fooBitset(digit);
- if (fooBitset.count() == numberOfOnes) {
- string foo = fooBitset.to_string<char, std::string::traits_type>();
- cout << foo.substr(100 - stringLength, 100) << endl;
- }
- }
- }
- int main() {
- std::vector<int> parameters = input();
- print_binary(parameters[0], parameters[1]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement