60分,求助

P1914 小书童——凯撒密码

goodsnack @ 2024-10-22 14:44:43

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <queue>
#include <cstring>
#include <set>
#include <map>
using namespace std;
const int N = 1e5 + 6;
int d_8[8][2] = {{1, 2}, {1, -2}, {2, 1}, {2, -1}, {-1, 2}, {-1, -2}, {-2, 1}, {-2, -1}};
int d_4[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int main()
{
  int n;
  cin >> n;
  string s;
  cin >> s;
  int len = s.size();
  if (n > 26)
    n %= 26;
  for (int i = 0; i < len; i++)
  {
    if (s[i] + n < 'z')
    {
      s[i] = s[i] + n;
    }
    else
    {
      s[i] = s[i] + n - 26;
    }
  }
  cout << s << endl;
  return 0;
}

by one_four_three @ 2024-10-22 15:05:43

@goodsnack

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

求壶关


by goodsnack @ 2024-10-22 15:12:21

@one_four_three 这样写会超时吧


by goodsnack @ 2024-10-22 15:13:03

@one_four_three 大数据不能这样处理...


by goodsnack @ 2024-10-22 15:16:17

@one_four_three 我调好了,'z'那里加个等号就好了,谢谢你


by one_four_three @ 2024-10-22 20:31:46

@goodsnack 这是AC代码。。。


|