60.......__^__

P1914 小书童——凯撒密码

lyl__lxly @ 2024-07-12 18:22:36

#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    int n;
    cin>>n>>s;
    int len=s.size();
    for(int i=0;i<len;i++)
    {
        if(s[i]-'a'+n>26)
        {
            s[i]=s[i]-(26-n);
        }
        else
        {
            s[i]+=n;
        }
    }
    cout<<s;
}

by lyl__lxly @ 2024-07-12 18:23:01

ding


by LRRabcd @ 2024-07-12 18:32:13

#include<iostream>
#include<cstring>
using namespace std;
int main(){
    string s;
    int n;
    cin>>n>>s;
    int len=s.size();
    for(int i=0;i<len;++i){
        for(int j=1;j<=n;j++){
            s[i]++;
            if(s[i]>'z'){
                s[i]='a';
            }               
        }
    }
    cout<<s;
    return 0;
}

by LRRabcd @ 2024-07-12 18:38:01

#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    int n;
    cin>>n>>s;
    int len=s.size();
    for(int i=0;i<len;i++)
    {
        if(s[i]-'a'+1+n>26)
        {
            s[i]=s[i]-(26-n);
        }
        else
        {
            s[i]+=n;
        }
    }
    cout<<s;
}

|