题解 | #简单密码#

简单密码

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

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner input=new Scanner(System.in);
		String string=input.nextLine();
		for (int i = 0; i < string.length(); i++) {
			String s=string.substring(i,i+1);
			//小写
			if (s.matches("[a-z]")) {
				if (s.matches("[a-c]")) {
					System.out.print(2);
				}
				if (s.matches("[d-f]")) {
					System.out.print(3);
				}
				if (s.matches("[g-i]")) {
					System.out.print(4);
				}
				if (s.matches("[j-l]")) {
					System.out.print(5);
				}
				if (s.matches("[m-o]")) {
					System.out.print(6);
				}
				if (s.matches("[p-s]")) {
					System.out.print(7);
				}
				if (s.matches("[t-v]")) {
					System.out.print(8);
				}
				if (s.matches("[w-z]")) {
					System.out.print(9);
				}
			}
			//数字
			if (s.matches("[0-9]")) {
				System.out.print(s);
			}
			//大写
			if (s.matches("[A-Y]")) {
				System.out.print((char)(s.charAt(0)+33));
			}
			if (s.matches("[Z]")) {
				System.out.print("a");
			}
		}
	}
}

全部评论

相关推荐

勤劳的鲸鱼在okr拆解:没有别的选择就去吧,有实习和没实习找工作是天上地下
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务