有序Set:LinkedHashSet

字符串加密

https://www.nowcoder.com/practice/e4af1fe682b54459b2a211df91a91cf3

import java.util.Scanner;
import java.util.LinkedHashSet;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        char[] str = "abcdefghijklmnopqrstuvwxyz".toCharArray();
        Scanner in = new Scanner(System.in);
        String s1 = in.nextLine();
        char[] c1 = s1.toCharArray();
        String s2 = in.nextLine();
        StringBuilder sb = new StringBuilder();
        LinkedHashSet<Character> s = new LinkedHashSet<>();
        for (int i = 0; i < c1.length; i++) {
            s.add(c1[i]);
        }
        for (int i = 0; i < str.length; i++) {
            s.add(str[i]);
        }
        Object[] array = s.toArray();
        for (int i = 0; i < s2.length(); i++) {
            int n = s2.charAt(i) - 'a';
            sb.append(array[n]);
        }
        System.out.println(sb);
    }
}
LinkedHashSet<Character> s = new LinkedHashSet<>();
Object[] array = s.toArray();
全部评论

相关推荐

钱嘛数字而已:拖拉机被发明出来之后,就不需要农民了吗?农民还是需要的,但不需要这么多了,另外对农民的要求也变高了,需要会开拖拉机。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务