Algorithm_ZRF @ 2023-08-29 17:21:25
#include <bits/stdc++.h>
using namespace std;
string a;
int n, b, c;
void shu_ru() {
cin >> n >> a;
}
void ji_suan() {
b = a.size();
n = n % 26;
for (int i = 0; i < b; ++i) {
if (n > (int)a[i]) {
c = (int)a[i];
}
}
n -= c;
for (int i = 0; i < b; ++i) {
a[i] += n;
}
}
void shu_chu() {
cout << a;
}
int main() {
shu_ru();
ji_suan();
shu_chu();
}
by dthythxth_Huge_Brain @ 2023-08-29 17:35:38
@AlgorithmArtist hack:
25
abcxyz
zabwxy
by dthythxth_Huge_Brain @ 2023-08-29 17:36:45
你的输出:
z{|憭
by Algorithm_ZRF @ 2023-08-29 17:37:21
@Huge_Brain 乱码了,为什么会这样?
by dthythxth_Huge_Brain @ 2023-08-29 17:43:21
@AlgorithmArtist 实际上你可以直接一个式子解决的:(a[i]-'a'+n)%26+'a'
by Algorithm_ZRF @ 2023-08-29 17:43:54
@Huge_Brain ?
by dthythxth_Huge_Brain @ 2023-08-29 17:44:25
#include<bits/stdc++.h>
using namespace std;
#define int long long
string str;
signed main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
int n;
cin>>n;
cin>>str;
for(int i=0;i<str.size();i++){
cout<<char((str[i]-'a'+n)%26+'a');
}
return 0;
}
by dthythxth_Huge_Brain @ 2023-08-29 17:45:29
@AlgorithmArtist
by Algorithm_ZRF @ 2023-08-29 21:59:43
@Huge_Brain thanks