不懂就问,我这代码水平是不是很烂...
是这样的,某boss交谈了一个小公司,给我发了笔试题,如图,我花了快五个小时才完善提交,大伙们看看啥水平。因为是手写要求,我拍照上传的,后边红色是IDEA运行成功后发给HR的,结果未通过笔试。
import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { char[] str = {'a','A','z','Z','b','B','c','C','x','X','d','D','w','W','e','E','v','V','f','F','u','U','g','G','t','T','h','H','s','S','i','I','r','R','j','J','q','Q','k','K','p','P','l','L','o','O','m','M','n','N'}; Scanner scanner = new Scanner(System.in); String line = scanner.nextLine(); char[] a = line.toCharArray(); char[] d = new char[a.length]; char[] f = new char[a.length]; char[] g = new char[a.length]; int[] num = new int[a.length]; int temp = 0; int b = 0; for (int i = 0; i < a.length; i++) { for (int j = 0; j < str.length; j++) { int e = a[i]; if (e < 65 || (90 < e && e <97) || e > 122){ f[b] = a[i]; b++; break; } else if (a[i] == str[j]){ num[temp] = j; g[temp] = str[j]; temp++; } } } int[] tes = new int[num.length-b]; int[] c = new int[num.length-b]; for (int l = 0; l < num.length - b; l++) { tes[l] = num[l]; } for (int x = 0; x < num.length-b; x++) { c[x] = num[x]; } Arrays.sort(tes); for (int y = 0; y < num.length-b; y++) { for (int z = 0; z < num.length-b; z++) { if (c[y] == tes[z]){ d[z] = g[y]; } } } for (int k = 0; k < num.length-b; k++) { System.out.print(d[k]); } for (int m = 0; m < b; m++) { System.out.print(f[m]); } } }