Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main() {
- string s;
- int k;
- cin >> s >> k;
- int n = s.size();
- int power_of_two = 1;
- for(int i = 0; i < n; i++){
- power_of_two *= 2;
- }
- power_of_two--;
- string answer = "";
- for(int i = 0; i < power_of_two; i++){
- int bin = i;
- int how_many_ones = 0;
- while(bin > 0){
- if(bin % 2 == 1){
- how_many_ones++;
- }
- bin /= 2;
- }
- if(how_many_ones == n - k){
- bin = i;
- string current_combination = "";
- int j = 0;
- while(bin > 0){
- if(bin % 2 == 1){
- current_combination += s[j];
- }
- j++;
- bin /= 2;
- }
- answer = max(answer, current_combination);
- }
- }
- cout << answer << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement