题解 | #简单密码# 大道至简

简单密码

https://www.nowcoder.com/practice/7960b5038a2142a18e27e4c733855dac

模拟

import java.io.*;
import java.util.*;

public class Main {
    static final int[] map = { 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9};

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);

        String str = br.readLine();
        pw.println(transform(str));

        pw.flush();
        pw.close();
        br.close();
    }

    private static String transform(String str) {
        StringBuilder builder = new StringBuilder();
        for (char c : str.toCharArray()) {
            if (Character.isUpperCase(c)) {
                c = Character.toLowerCase(c);
                c = (char) ((c - 'a' + 1) % 26 + 'a');
                builder.append(c);
            } else if (Character.isLowerCase(c)) {
                builder.append(map[c - 'a']);
            } else {
                builder.append(c);
            }
        }
        return builder.toString();
    }
}
全部评论
(c –'a'+1)%26+'a' 是啥意思啊
点赞 回复 分享
发布于 2023-04-04 23:32 北京

相关推荐

13 3 评论
分享
牛客网
牛客企业服务