在一行上输入一个长度为
的字符串
,代表给定的密码。
在一行上输出一个字符串,代表变换后的密码。
NowCoder123
o69d6337123
import java.util.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 while (in.hasNextLine()) { // 注意 while 处理多个 case //输入 String str = in.nextLine(); //为空或者超长则退出 if (str.isEmpty() || str.length() > 100 ) { break; } StringBuilder result = new StringBuilder(); for (char c : str.toCharArray()) { //处理小写字母 if (Character.isLowerCase(c)) { //如果c在字符串中存在,则进入if if ("abc".indexOf(c) != -1) { result.append("2"); } if ("def".indexOf(c) != -1) { result.append("3"); } if ("ghi".indexOf(c) != -1) { result.append("4"); } if ("jkl".indexOf(c) != -1) { result.append("5"); } if ("mno".indexOf(c) != -1) { result.append("6"); } if ("pqrs".indexOf(c) != -1) { result.append("7"); } if ("tuv".indexOf(c) != -1) { result.append(8); } if ("wxyz".indexOf(c) != -1) { result.append(9); } } //处理大写字母 if (Character.isUpperCase(c)) { if (c == 'Z') { //对Z进行特殊处理 result.append("a"); } else { //不是Z的话,将字符转为小写,并且char+1得到下一位小写字母,加入到结果中 char temp = Character.toLowerCase(c) ; char[] s = Character.toChars(temp + 1); result.append(s); } } //处理数字 if (Character.isDigit(c)) { result.append(c); } } System.out.println(result); } // in.close(); } }
import java.util.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 String target = in.nextLine(); char[] ch = target.toCharArray(); char[] ch1 = new char[ch.length]; for (int i = 0 ; i < ch.length; i++) { if (Character.isLowerCase(ch[i])) { if (ch[i] == 'a' || ch[i] == 'b' || ch[i] == 'c') { ch1[i] = '2'; } else if (ch[i] == 'd' || ch[i] == 'e' || ch[i] == 'f') { ch1[i] = '3'; } else if (ch[i] == 'g' || ch[i] == 'h' || ch[i] == 'i') { ch1[i] = '4'; } else if (ch[i] == 'j' || ch[i] == 'k' || ch[i] == 'l') { ch1[i] = '5'; } else if (ch[i] == 'm' || ch[i] == 'n' || ch[i] == 'o') { ch1[i] = '6'; } else if (ch[i] == 'p' || ch[i] == 'q' || ch[i] == 'r' || ch[i] == 's') { ch1[i] = '7'; } else if (ch[i] == 't' || ch[i] == 'u' || ch[i] == 'v') { ch1[i] = '8'; } else if (ch[i] == 'w' || ch[i] == 'x' || ch[i] == 'y' || ch[i] == 'z') { ch1[i] = '9'; } } else if (Character.isUpperCase(ch[i])) { ch1[i] = Character.toLowerCase(ch[i]); if (ch1[i] == 'z') { ch1[i] = 'a'; } else { ch1[i] = (char)(ch1[i] + 1); } } else if (Character.isDigit(ch[i])) { ch1[i] = ch[i]; } } String result = String.valueOf(ch1); System.out.println(result); } }
import java.util.Arrays; import java.util.Collections; import java.util.Map; import java.util.Scanner; import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 while (in.hasNext()) { // 注意 while 处理多个 case System.out.println(encodePassword(in.nextLine())); } } private static String encodePassword(String password){ //返回加密密码 String encodePassword = ""; Map<String,String> dictMap = new ConcurrentHashMap<>(); // 字典表 String a = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; String b = "1234567890bcdefghijklmnopqrstuvwxyza22233344455566677778889999"; for(int i = 0 ;i < a.length(); i++){ dictMap.put(Character.toString(a.charAt(i)),Character.toString(b.charAt(i))); } encodePassword = Arrays.stream(password.split("")).map(s->dictMap.get(s)).collect(Collectors.joining("")); return encodePassword; } }
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int[] index = {2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,7,8,8,8,9,9,9,9}; char[] input = in.nextLine().toCharArray(); for(int i=0; i<input.length; i++) { if(input[i]>='0' && input[i]<='9') { System.out.print(input[i]); continue; } if(input[i]>='a' && input[i]<='z') { System.out.print(index[input[i]-'a']); continue; } if(input[i]>='A' && input[i]<'Z') { System.out.print((char)(input[i]-'A'+'a'+1)); continue; } if(input[i]=='Z') { System.out.print('a'); } } } }
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); String line = in.nextLine(); String password = simplePassword(line); System.out.println(password); } private static char[] map = new char[128]; static { map['a'] = '2';map['b'] = '2';map['c'] = '2'; map['d'] = '3';map['e'] = '3';map['f'] = '3'; map['g'] = '4';map['h'] = '4';map['i'] = '4'; map['j'] = '5';map['k'] = '5';map['l'] = '5'; map['m'] = '6';map['n'] = '6';map['o'] = '6'; map['p'] = '7';map['q'] = '7';map['r'] = '7';map['s'] = '7'; map['t'] = '8';map['u'] = '8';map['v'] = '8'; map['w'] = '9';map['x'] = '9';map['y'] = '9';map['z'] = '9'; for (char c = 'A'; c < 'Z'; c++) { map[c] = (char) (c - 'A' + 'a'+1); } for (char c = '0'; c <= '9'; c++) { map[c] = c; } map['Z'] = 'a'; } private static String simplePassword(String line) { char[] arr = line.toCharArray(); for (int i = 0; i < arr.length; i++) { char c = arr[i]; char nc = map[c]; arr[i] = nc; } return new String(arr); } }
import java.util.Scanner; public class hj21 { public static void main(String[] args) { Scanner in = new Scanner(System.in); String str = in.nextLine(); for (int i = 0; i < str.length(); i++) { char c = str.charAt(i); if(c >= 'A' && c <= 'Z'){ c = (char) ((c + 33-97)%26 +97); }else if(c >= 'a' && c <= 'c'){ c = '2'; }else if(c >= 'd' && c <= 'f'){ c = '3'; }else if(c >= 'g' && c <= 'i'){ c = '4'; }else if(c >= 'j' && c <= 'l'){ c = '5'; }else if(c >= 'm' && c <= 'o'){ c = '6'; }else if(c >= 'p' && c <= 's'){ c = '7'; }else if(c >= 't' && c <= 'v'){ c = '8'; }else if(c >= 'w' && c <= 'z'){ c = '9'; } System.out.print(c); } } }
public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.nextLine(); char[] chars = s.toCharArray(); StringBuilder sb = new StringBuilder(); for (char c : chars) { // 如果是正整数就不需要加密 if (c >= '0' && c <= '9') { sb.append(c); } else if (c >= 'A' && c <= 'Y') { // 如果是大写字母 那么就将其转为小写字母并且后移一位 char c1 = (char) (c + 32 + 1); sb.append(c1); } else if (c == 'Z') { sb.append('a'); } else { // 小写字母进行map校验 switch (c) { case 1: sb.append(1); break; case 'a': case 'b': case 'c': sb.append(2); break; case 'd': case 'e': case 'f': sb.append(3); break; case 'g': case 'h': case 'i': sb.append(4); break; case 'j': case 'k': case 'l': sb.append(5); break; case 'm': case 'n': case 'o': sb.append(6); break; case 'p': case 'q': case 'r': case 's': sb.append(7); break; case 't': case 'u': case 'v': sb.append(8); break; case 'w': case 'x': case 'y': case 'z': sb.append(9); break; case '0': sb.append(0); break; } } } System.out.println(sb); }
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 String str = in.nextLine(); //1. 小写字母转九键 // for(int i = 0;i < str.length();i++){ // switch(str.charAt(i)){ // case 'a','b','c': // str.replace() // } // } str = str.replace('a','2') .replace('b','2') .replace('c','2') .replace('d','3') .replace('e','3') .replace('f','3') .replace('g','4') .replace('h','4') .replace('i','4') .replace('j','5') .replace('k','5') .replace('l','5') .replace('m','6') .replace('n','6') .replace('o','6') .replace('p','7') .replace('q','7') .replace('r','7') .replace('s','7') .replace('t','8') .replace('u','8') .replace('v','8') .replace('w','9') .replace('x','9') .replace('y','9') .replace('z','9') //2. 大写字母小写之后后移一位 .replace('A','b') .replace('B','c') .replace('C','d') .replace('D','e') .replace('E','f') .replace('F','g') .replace('G','h') .replace('H','i') .replace('I','j') .replace('J','k') .replace('K','l') .replace('L','m') .replace('M','n') .replace('N','o') .replace('O','p') .replace('P','q') .replace('Q','r') .replace('R','s') .replace('S','t') .replace('T','u') .replace('U','v') .replace('V','w') .replace('W','x') .replace('X','y') .replace('Y','z') .replace('Z','a'); //输出 System.out.println(str); } }
import java.util.HashMap; import java.util.Map; import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); String str = in.nextLine(); 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"); StringBuilder stb = new StringBuilder(); for (int i = 0; i < str.length(); i++) { String s = str.charAt(i)+""; if (s.matches("[A-Z]")) { s = s.toLowerCase(); if ("z".equals(s)) { stb.append("a"); } else { char c = s.charAt(0); stb.append((char) (c+1)); } } else { stb.append(s); } } System.out.println(stb); } }
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in=new Scanner(System.in); String str=in.nextLine(); for(int i=0;i<str.length();i++){ if(str.charAt(i)>='a'&&str.charAt(i)<='c'){ System.out.print("2"); }else if(str.charAt(i)>='d'&&str.charAt(i)<='f'){ System.out.print("3"); }else if(str.charAt(i)>='g'&&str.charAt(i)<='i'){ System.out.print("4"); }else if(str.charAt(i)>='j'&&str.charAt(i)<='l'){ System.out.print("5"); }else if(str.charAt(i)>='m'&&str.charAt(i)<='o'){ System.out.print("6"); }else if(str.charAt(i)>='p'&&str.charAt(i)<='s'){ System.out.print("7"); }else if(str.charAt(i)>='t'&&str.charAt(i)<='v'){ System.out.print("8"); }else if(str.charAt(i)>='w'&&str.charAt(i)<='z'){ System.out.print("9"); }else if(str.charAt(i)>='A'&&str.charAt(i)<='Y'){ System.out.print((char)((int)str.charAt(i)+33)); }else if(str.charAt(i)=='Z'){ System.out.print("a"); }else{ System.out.print(str.charAt(i)); } } } }
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); char[] str=in.nextLine().toCharArray(); for(int i=0;i<str.length;i++){ System.out.print(parse(str[i])); } } private static char parse(char c){ if(c>='a'&&c<='z'){ if(c>='a'&&c<='c'){ return '2'; } if(c>='d'&&c<='f'){ return '3'; } if(c>='g'&&c<='i'){ return '4'; } if(c>='j'&&c<='l'){ return '5'; } if(c>='m'&&c<='o'){ return '6'; } if(c>='p'&&c<='s'){ return '7'; } if(c>='t'&&c<='v'){ return '8'; } if(c>='w'&&c<='z'){ return '9'; } } if(c>='A'&&c<='Z'){ return (char)((c-'A'+1)%26+'a'); } return c; } }