题解 | #字符串加密#

字符串加密

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

Java小白解法;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String str = sc.nextLine();
            String s = sc.nextLine();
            char[] stand = new char[] {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
            Set<Character> set = new LinkedHashSet<>();
            for (int i = 0; i < str.length(); i++) {
                if (!set.contains(str.charAt(i))) {
                    set.add(str.charAt(i));
                }
            }
            for (int i = 0; i < stand.length; i++) {
                if (!set.contains(stand[i])) {
                    set.add(stand[i]);
                }
            }
            int index = 0;
            char[] arr = new char[26];
            for (Character c : set) {
                arr[index++] = c;
            }
            String ss = "";
            for (int i = 0; i < s.length(); i++) {
                char c = s.charAt(i);
                for (int j = 0; j < 26; j++) {
                    if (stand[j] == c) {
                        ss += arr[j];
                    }
                }
            }
            System.out.print(ss);
        }
    }
}


#小白的技术进阶日记#
全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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