【golang】有无大佬帮忙看下这个代码为什么不行,自测没问题,一提交全红www

P1914 小书童——凯撒密码

wanlxj0429 @ 2021-02-24 14:23:26

package main
import(
    "fmt"
)
func main(){
    var(
        str [50]byte
        n int
    )
    fmt.Scanf("%d",&n)
    for i := 0;str[i] != '\n';i ++{
        fmt.Scanf("%c",&str[i])
        if str[i] == '\n'{
            break
        }
        for j := 0;j < n;j ++{
            if str[i] != 'z'{
                str[i] = str[i] + 1
            }else{
                str[i] = 'a'
            }
        }
    }
    for i := 0;i < len(str);i ++{
        fmt.Printf("%c",str[i])
    }
    fmt.Printf("\n")
}

by _Rainlzy @ 2021-02-24 14:27:48

@wanlxj0429 你这语言咋就这么奇怪呢


by impuk @ 2021-02-24 14:28:14

@_Rainlzy 看不懂就别回复


by impuk @ 2021-02-24 14:30:41

好像是len(str)爆炸了


by impuk @ 2021-02-24 14:31:07

试试看把第一个循环内的8保存起来


by impuk @ 2021-02-24 14:31:33

8 -》 i 打错了


|