洛谷 P1914 小书童——凯撒密码

2022-07-28,,

洛谷 P1914 小书童——凯撒密码

水题

  • 用(s[i]-‘a’+n)%26+'a’来进行字母的变换

贴代码:

/*
 * @Description: 
 * @Author: 多多
 * @Date: 2020-10-24 10:17:53
 * @LastEditTime: 2020-10-24 11:06:56
 * @LastEditors: 多多
 */
#include <bits/stdc++.h>
using namespace std;

int main()
{
    freopen("P1914.in", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    string s;
    cin >> s;
    for (int i = 0; i < s.length(); i++)
    {
        s[i] = (s[i] - 'a' + n) % 26 + 'a';
    }
    cout << s << endl;
    return 0;
}

本文地址:https://blog.csdn.net/weixin_39117125/article/details/109256348

《洛谷 P1914 小书童——凯撒密码.doc》

下载本文的Word格式文档,以方便收藏与打印。