Advertisement
Josif_tepe

Untitled

Feb 28th, 2022
883
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. int main() {
  6.     string s;
  7.     cin >> s;
  8.     int k;
  9.     cin >> k;
  10.    
  11.     int n = s.size();
  12.     string result = "";
  13.     for(int mask = 0; mask < (1 << n); mask++) {
  14.         int bitcount = 0;
  15.         string tmp = "";
  16.         for(int i = 0; i < n; i++) {
  17.             if(mask & (1 << i)) {
  18.                 bitcount++;
  19.             }
  20.             else {
  21.                 tmp += s[i];
  22.             }
  23.         }
  24.         if(bitcount == k) {
  25.             result = max(result, tmp);
  26.         }
  27.     }
  28.     cout << result << endl;
  29.     return 0;
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement