题解 | #字符串加解密#

字符串加解密

https://www.nowcoder.com/practice/2aa32b378a024755a3f251e75cbf233a

package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func main() {
	str1 := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
	str2 := "BCDEFGHIJKLMNOPQRSTUVWXYZAbcdefghijklmnopqrstuvwxyza1234567890"

	in := bufio.NewScanner(os.Stdin)
	in.Scan()
	s1 := in.Text()
	in.Scan()
	s2 := in.Text()

	encode := make([]byte, len(s1))
	for i, s := range s1 {
		encode[i] = str2[strings.Index(str1, string(s))]
	}
	decode := make([]byte, len(s2))
	for i, s := range s2 {
		decode[i] = str1[strings.Index(str2, string(s))]
	}

	fmt.Println(string(encode))
	fmt.Println(string(decode))
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-09 12:05
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-08 11:16
点赞 评论 收藏
分享
05-30 12:03
山西大学 C++
offer来了我跪着...:不是骗子,等到测评那一步就知道为啥这么高工资了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务