题解 | #简单密码#

简单密码

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

import java.util.HashMap;
import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        // while (in.hasNextInt()) { // 注意 while 处理多个 case
        //     int a = in.nextInt();
        //     int b = in.nextInt();
        //     System.out.println(a + b);
        // }

        String str=in.next();
        HashMap<Character,Integer> myMap=new HashMap<>();
        myMap.put('a',2);
        myMap.put('b',2);
        myMap.put('c',2);
        myMap.put('d',3);
        myMap.put('e',3);
        myMap.put('f',3);
        myMap.put('g',4);
        myMap.put('h',4);
        myMap.put('i',4);
        myMap.put('j',5);
        myMap.put('k',5);
        myMap.put('l',5);
        myMap.put('m',6);
        myMap.put('n',6);
        myMap.put('o',6);
        myMap.put('p',7);
        myMap.put('q',7);
        myMap.put('r',7);
        myMap.put('s',7);
        myMap.put('t',8);
        myMap.put('u',8);
        myMap.put('v',8);
        myMap.put('w',9);
        myMap.put('x',9);
        myMap.put('y',9);
        myMap.put('z',9);
        int len=str.length();
        StringBuilder strBuilder=new StringBuilder();
        for(int i=0;i<len;i++){
            if(Character.isDigit(str.charAt(i))){
                strBuilder.append(str.charAt(i));
            }else if(Character.isLowerCase(str.charAt(i))){
                strBuilder.append(myMap.get(str.charAt(i)));
            }else{
                if(str.charAt(i)=='Z'){
                    strBuilder.append('a');
                }else{
                    strBuilder.append((char)(str.charAt(i)+('a'-'A')+1)); //'a'97   'A'65
                }
            }
        }
        System.out.println(strBuilder);





    }
}

全部评论

相关推荐

能干的三文鱼刷了10...:公司可能有弄嵌入式需要会画pcb的需求,而且pcb能快速直观看出一个人某方面的实力。看看是否有面试资格。问你问题也能ai出来,pcb这东西能作假概率不高
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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