danielvitor23

Runas mágicas

Jul 29th, 2023
1,043
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define fi first
  3. #define se second
  4. using namespace std;
  5.  
  6. using i64 = long long;
  7.  
  8. int main() {
  9.   cin.tie(0)->sync_with_stdio(0);
  10.  
  11.   string s; cin >> s;
  12.   int d; cin >> d;
  13.   int n = s.size();
  14.  
  15.   reverse(s.begin(), s.end());
  16.  
  17.   i64 curr = 0;
  18.   for (int i = 0; i < (int)s.size(); ++i) {
  19.     curr <<= 1;
  20.     if (s[i] == 'B')
  21.       curr += 1;
  22.   }
  23.  
  24.   // cout << curr << '\n';
  25.  
  26.   curr += d;
  27.  
  28.   string res;
  29.   while (curr > 0) {
  30.     res += ((curr & 1) ? 'B' : 'A');
  31.     curr >>= 1;
  32.   }
  33.  
  34.   while (res.size() < n) res = res + 'A';
  35.   while (res.size() > n) res.pop_back();
  36.  
  37.   cout << res << '\n';
  38. }
Advertisement
Add Comment
Please, Sign In to add comment