P1914 小书童——密码

P1914 小书童——密码

ASCII 表

题解

1.本题都是小写字母唉

2.把字母取模27   得到对应单词表顺序1···26

3.后移并且取模26  如果得到0,那么证明它是 z (122),否则对应加上96,回归对应字母

代码

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>

using namespace std;

int n;
char s[51];

int main()
{
    scanf("%d
",&n);
    gets(s);
    for(int i=0;i<=strlen(s)-1;i++)
    {
        s[i]=(s[i]-96)%27;
        s[i]=(s[i]+n)%26;
if(s[i]==0) s[i]=122;
else s[i]+=96;

    }
    for(int i=0;i<=strlen(s)-1;i++)
      printf("%c",s[i]);
    
}
原文地址:https://www.cnblogs.com/xiaoyezi-wink/p/10963369.html