题解 | #字符串加密#
字符串加密
https://www.nowcoder.com/practice/e4af1fe682b54459b2a211df91a91cf3
HJ36()
func HJ36() {
guard let key = readLine(), let word = readLine() else { return }
let normal = "abcdefghijklmnopqrstuvwxyz"
var indexes = [String.Index]()
for c in word {
indexes.append( normal.firstIndex(of: c)! )
}
var neww = ""
for c in key {
if !neww.contains(c) {
neww.append(c)
}
}
for c in normal {
if !neww.contains(c) {
neww.append(c)
}
}
var result = ""
for idx in indexes {
result.append(neww[idx])
}
print(result)
}
func HJ36() {
guard let key = readLine(), let word = readLine() else { return }
let normal = "abcdefghijklmnopqrstuvwxyz"
var indexes = [String.Index]()
for c in word {
indexes.append( normal.firstIndex(of: c)! )
}
var neww = ""
for c in key {
if !neww.contains(c) {
neww.append(c)
}
}
for c in normal {
if !neww.contains(c) {
neww.append(c)
}
}
var result = ""
for idx in indexes {
result.append(neww[idx])
}
print(result)
}