帮忙

P1914 小书童——凯撒密码

可乐爽 @ 2020-05-29 21:36:26

大佬们,教教我吧!

代码如下:


#include<cstdio>
#include<iostream> 
using namespace std;
const int maxn=50+5;
char a[maxn];
int n; 
int main()         
{     
    cin>>n;
    cin>>a;
    for(int i=0;i<=55;i++){
        a[i]=a[i]+n;
        if(a[i]>'z')
            a[i]=a[i]-26;
        cout<<a[i];
    }
    return 0;       
 }  
帮帮忙

by bird_秒切橙题 @ 2020-05-29 21:38:22

帮帮忙去掉就不会编译错误了


by bird_秒切橙题 @ 2020-05-29 21:41:05

#include<bits/stdc++.h>
using namespace std;
char a[1001];
int n; 
int main()         
{     
    cin>>n;
    cin>>a;
    for(int i=0;i<strlen(a);i++){
        a[i]=a[i]+n;
        if(a[i]>'z')
            a[i]=a[i]-26;
        cout<<a[i];
    }
    return 0;       
 }  

by bird_秒切橙题 @ 2020-05-29 21:41:16

@可乐爽


by JRzyh @ 2020-05-29 21:43:19

@small_bird strlen是n的,您的代码是 n^2的


by bird_秒切橙题 @ 2020-05-29 21:45:21

#include<bits/stdc++.h>
using namespace std;
char s[1001];
int n;
int main()
{
    cin>>n>>s;
    for(int i=0;i<=strlen(s)-1;i++)
    {
        int k=s[i]+n;
        while(k>'z')k-=26;
        cout<<char(k);
    }
}

by bird_秒切橙题 @ 2020-05-29 21:45:31

@可乐爽


by HyyypRtf06 @ 2020-05-29 21:45:43

@Zhaoyuhang2008 题水,n^4都OK


by HyyypRtf06 @ 2020-05-29 21:46:29

当然strlen写成这样也是很……

size是O(1)的


by bird_秒切橙题 @ 2020-05-29 21:47:05

没事反正都可以比赛的时候我才这样写


by 可乐爽 @ 2020-06-01 13:04:30

谢谢,已解决


|