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",&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]);
    
}

 

posted @ 2019-06-02 16:40  晔子  阅读(441)  评论(0编辑  收藏  举报