AcWing 3405. W的密码
原题链接
简单
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int N = 1e2 + 10;
int t, n, m, k, l, r, op, x, y;
int k1, k2, k3;
string str,ans;
struct nd {
char ch;
int pos;
};
nd mp1[N], mp2[N], mp3[N];
int f1[N],f2[N],f3[N];
int idx1, idx2, idx3;
void solve() {
while (cin >> k1 >> k2 >> k3) {
if (k1 == 0 && k2 == 0 && k3 == 0)return;
idx1=idx2=idx3=0;
cin >> str;
int siz = str.size();
for (int i = 0; i < siz; i++) {
char ch = str[i];
if (ch >= 'a' && ch <= 'i') {
mp1[++idx1] = {ch, i};
f1[idx1] = i;
} else if (ch >= 'j' && ch <= 'r') {
mp2[++idx2] = {ch, i};
f2[idx2] = i;
} else {
mp3[++idx3] = {ch, i};
f3[idx3] = i;
}
}
for(int i = 1;i<=idx1;i++){
mp1[i].pos = f1[(i+k1-1)%idx1+1];
}
for(int i = 1;i<=idx2;i++){
mp2[i].pos = f2[(i+k2-1)%idx2+1];
}
for(int i = 1;i<=idx3;i++){
mp3[i].pos = f3[(i+k3-1)%idx3+1];
}
ans.resize(siz);
for(int i = 1;i<=idx1;i++){
ans[mp1[i].pos] = mp1[i].ch;
}
for(int i = 1;i<=idx2;i++){
ans[mp2[i].pos] = mp2[i].ch;
}
for(int i = 1;i<=idx3;i++){
ans[mp3[i].pos] = mp3[i].ch;
}
cout<<ans<<"\n";
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
solve();
return 0;
}