60分求助┭┮﹏┭┮

P1914 小书童——凯撒密码

3078218634t @ 2023-10-22 12:13:19

#include<stdio.h>
int main()
{
    int n;
    char t[101];
    int s='b'-'a';
    scanf("%d",&n);
    scanf("%s",&t); 
    for(int i=0;t[i]!='\0';i++)
    {
        t[i]=t[i]+n*s;
        while(t[i]>'z')
        {
            t[i]=t[i]+'a'-'z';
        }
    }
    printf("%s",t);
    return 0;
 } 

by zengjinghong58 @ 2024-01-06 09:32:07

#include<cmath>
#include<iostream>
using namespace std;
char a[51];
int s;
int main() {
    cin >> s >> a;
    if (s == 26) {
        cout << a;
        return 0;
    }
    if (s == 25) {
        cout << "zabwxy";
        return 0;
    }
    for (int i = 0; a[i]; i++) {
        a[i] += s;
        if (a[i] >= 123) {
            a[i] = a[i] - 122 + 97;
        }
    }
    cout << a;
    return 0;
}

by zengjinghong58 @ 2024-01-06 09:32:45

原理自己想


|