题解 | #简单密码#

简单密码

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

import java.util.*;


public class Main{
    public static void main(String[] arg){
        Scanner sc=new Scanner(System.in);
        String str=sc.nextLine();
        StringBuffer buffer = new StringBuffer();
        Map<Character, Integer> map = new HashMap<>();
        map.put('a',2);
        map.put('b',2);
        map.put('c',2);
        map.put('d',3);
        map.put('e',3);
        map.put('f',3);
        map.put('g',4);
        map.put('h',4);
        map.put('i',4);
        map.put('j',5);
        map.put('k',5);
        map.put('l',5);
        map.put('m',6);
        map.put('n',6);
        map.put('o',6);
        map.put('p',7);
        map.put('q',7);
        map.put('r',7);
        map.put('s',7);
        map.put('t',8);
        map.put('u',8);
        map.put('v',8);
        map.put('w',9);
        map.put('x',9);
        map.put('y',9);
        map.put('z',9);

        for(int i=0;i<str.length();i++){
            if('A'<=str.charAt(i)&&str.charAt(i)<'Z'){
                buffer.append(""+(char)(str.charAt(i)+33));
            }else if(str.charAt(i)=='Z'){
                buffer.append(""+(char)(str.charAt(i)+7));
            }else if('a'<=str.charAt(i)&&str.charAt(i)<='z'){
                buffer.append(""+map.get(str.charAt(i)));
            }else if('0'<=str.charAt(i)&&str.charAt(i)<='9'){
                buffer.append(""+str.charAt(i));
            }
        }        

        System.out.println(buffer);
    }
}
全部评论

相关推荐

刘苏杰:应届生春招面试四五十分钟,最后问有几个offer,但没有谈薪资,是什么情况?焦虑不安
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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