SHARE
TWEET

Untitled

a guest Jul 16th, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5.      string s;
  6.      int k;
  7.      cin >> s >> k;
  8.      int n = s.size();
  9.      int power_of_two = 1;
  10.      for(int i = 0; i < n; i++){
  11.          power_of_two *= 2;
  12.      }
  13.      power_of_two--;
  14.      string answer = "";
  15.      for(int i = 0; i < power_of_two; i++){
  16.          int bin = i;
  17.          int how_many_ones = 0;
  18.          while(bin > 0){
  19.              if(bin % 2 == 1){
  20.                  how_many_ones++;
  21.              }
  22.              bin /= 2;
  23.          }
  24.          if(how_many_ones == n - k){
  25.              bin = i;
  26.              string current_combination = "";
  27.              int j = 0;
  28.              while(bin > 0){
  29.                  if(bin % 2 == 1){
  30.                      current_combination += s[j];
  31.                  }
  32.                  j++;
  33.                  bin /= 2;
  34.              }
  35.              answer = max(answer, current_combination);
  36.          }
  37.      }
  38.      cout << answer << endl;
  39.     return 0;
  40. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top