题解 | #字符串加密#
字符串加密
https://www.nowcoder.com/practice/e4af1fe682b54459b2a211df91a91cf3
import java.util.LinkedList; import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String key = scanner.nextLine(); String str = scanner.nextLine(); String res = ""; LinkedList<Character> list = new LinkedList<>(); for (int i = 0; i < key.length(); i++) { if (!list.contains(key.charAt(i))) list.add(key.charAt(i)); } for (int i = 0; i < 26; i++) { char c = (char) ((char) 'a' + i); if (!list.contains(c)) list.add(c); } for (int i = 0; i < str.length(); i++) { int index = str.charAt(i) - 'a'; char c = list.get(index); res += String.valueOf(c); } System.out.println(res); } }