题解:B4563 [山东省小学组体验营 2026] 星际密信
题意
给定一个长度为
思路
把
遍历时:
- 遇到数字,直接输出。
- 遇到大写字母, 转成
0 \sim 25 的整数并加上偏移量, 对26 取模,然后转成大写字母输出即可。
code:
#include <bits/stdc++.h>
using namespace std;
int n,k,a;
string s;
const int mod=26;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin>>n>>k;
cin>>s;
a=k%26;
if(a<0){
a+=26;
}
for(char c:s){
if(c>='0'&&c<='9'){
cout<<c;
}else{
int b=c-'A';
b=(b+a)%mod;
cout<<char(b+'A');
}
}
return 0;
}