题解 | #简单密码#

简单密码

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

import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {

    public static void main(String[] args) {
        String map="22233344455566677778889999";
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String str = in.nextLine();
            StringBuilder sb = new StringBuilder();
            for(int i=0;i<str.length();i++) {
                char c = str.charAt(i);
                if(c>='0'&&c<='9'){
                    sb.append(c);
                } else if(c>='a'&&c<='z') {
                    sb.append(map.charAt(c-'a'));
                } else if(c>='A'&&c<='Z') {
                    if(c == 'Z') {
                        sb.append('a');
                    } else {
                        sb.append((char)(c+33));
                    }
                }
                
            }
            System.out.println(sb.toString());

        }
    }
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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