题解 | #字符串加密#
字符串加密
https://www.nowcoder.com/practice/e4af1fe682b54459b2a211df91a91cf3
import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); char[] key = in.nextLine().toCharArray(); char[] pass = in.nextLine().toCharArray(); LinkedHashSet<Character> set = new LinkedHashSet<>(); for(char index : key){ set.add(index); } for(char i='a'; i<='z'; i++){ set.add(i); } ArrayList<Character> array = new ArrayList<>(set); for(char index : pass){ int n = (int)index -(int)'a'; System.out.print(array.get(n)); } } }