把字符串翻转之后处理会更加方便
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define rep(i,a,b) for(ll i=(a);i<=(b);i++)
#define dec(i,a,b) for(ll i=(a);i>=(b);i--)
#define pll pair<ll,ll>
using namespace std;
ll INF = 0x7f7f7f7f7f7f7f7f;
const int N = 2e5 + 5;
ll mod = 998244353;
ll n, k, x;
string s;
int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll T;
cin >> T;
while (T--) {
cin >> n >> k >> x >> s;
x--;
reverse(s.begin(), s.end());
string ans = "";
ll i = 0;
while (i < n) {
if (s[i] == 'a') {
ans += s[i];
}
else {
ll j = i;
while (j + 1 < n && s[j + 1] == s[i]) {
j++;
}
ll cur = (j - i + 1) * k + 1;
rep(k, 1, x % cur) {
ans += 'b';
}
x /= cur;
i = j;
}
i++;
}
reverse(ans.begin(), ans.end());
cout << ans << '\n';
}
return 0;
}
原文链接: https://www.cnblogs.com/dealer/p/15805923.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/185751
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!