题解 | #简单密码#

简单密码

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

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String str = reader.readLine();
        str = str
            .replaceAll("[abc]", "2")
            .replaceAll("[def]", "3")
            .replaceAll("[ghi]", "4")
            .replaceAll("[jkl]", "5")
            .replaceAll("[mno]", "6")
            .replaceAll("[pqrs]", "7")
            .replaceAll("[tuv]", "8")
            .replaceAll("[wxyz]", "9").toLowerCase();
        StringBuilder result = new StringBuilder(str.length());
        for (int i = 0; i < str.length(); i++) {
            char temp = str.charAt(i);
            if (temp == 'z') temp = 'a';
            else if (temp - 'a' >= 0) temp = (char) (temp + 1);
            result.append(temp);
        }
        System.out.println(result);
    }
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-11 11:25
点赞 评论 收藏
分享
昨天 14:14
门头沟学院 Java
7.10投递7.15感谢信
投递地平线等公司8个岗位
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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