题解 | #字符串加密#
字符串加密
http://www.nowcoder.com/practice/e4af1fe682b54459b2a211df91a91cf3
import java.util.HashSet;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String key = sc.nextLine();
String s = sc.nextLine();
StringBuilder sb = new StringBuilder();
StringBuilder res = new StringBuilder();
HashSet<Character> set = new HashSet<>();
for (int i = 0; i < key.length(); i++) {
if(set.add(key.charAt(i))){
sb.append(key.charAt(i));
}
}
for(char i='a';i<='z';i++){
if(!set.contains(i)){
sb.append(i);
}
}
for (int i = 0; i < s.length(); i++) {
char c = sb.toString().charAt(s.charAt(i) - 'a');
res.append(c);
}
System.out.println(res.toString());
}
}