| #字符串加密#
字符串加密
https://www.nowcoder.com/practice/e4af1fe682b54459b2a211df91a91cf3
import java.util.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); scanner.useDelimiter("\n"); while (scanner.hasNext()){ String key = scanner.next(); String original = scanner.next(); //原始map,26个英文字母 StringBuilder map = new StringBuilder("abcdefghijklmnopqrstuvwxyz"); //去重用 HashSet<Character> hashSet = new HashSet<>(); for (int i = 0,j=0; i < key.length(); i++) { char c = key.charAt(i); if (!hashSet.contains(c)){ hashSet.add(c); //先删除原有顺序中的字母 map.deleteCharAt(map.indexOf(c+"")); //依次插入 map.insert(j++, c); } } for (int i = 0; i < original.length(); i++) { char c = original.charAt(i); //map下标从0开始,小写英文从97开始,要减去97 System.out.print(map.charAt(c-97)); } } } }