题解:T797805 [Algo Beat 013 & MSOI R2] 付之一笑
思路
按照题面直接模拟即可,从左到右遍历字符串。
当 char(x + 'a' - 1)。
当 c - 'a' + 1。
总时间复杂度为
代码
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int q;
cin >> q;
while(q--){
int p;
string s;
cin >> p >> s;
for(int i = 0; i < s.size(); i++){
if(p == 1 && isdigit(s[i])){
int x = s[i] - '0';
if(i + 1 < s.size() && isdigit(s[i + 1])){
x = x * 10 + s[++i] - '0';
}
cout << char('a' + x - 1);
}
else if(p == 2 && isalpha(s[i])){
cout << s[i] - 'a' + 1;
}
else{
cout << s[i];
}
}
cout << '\n';
}
return 0;
}