网易雷火笔试8.14 总共过了1.8
第一题 AC
public static void main(String[] args) { Scanner sc = new Scanner(System.in); String sin = sc.nextLine(); String substringIn = sin.substring(1, sin.length()); String[] splits = substringIn.split("]"); int[][] nums = new int[splits.length][]; for (int i = 0; i < splits.length; i++) { splits[i] = splits[i].replace('[', ' '); splits[i]=splits[i].replace(']',' '); splits[i]=splits[i].replace(',',' '); splits[i]= splits[i].replaceAll(" ",""); int[] ints = new int[splits[i].length()]; for (int j = 0; j < ints.length; j++) { ints[j] = splits[i].charAt(j)-'0'; } nums[i] = ints; } boolean[] isOpen = new boolean[nums.length]; isOpen[0] = true; openFor(nums,isOpen,0); boolean isOpenFull = true; for (boolean b : isOpen) { if(b==false) isOpenFull = false; } if (isOpenFull) System.out.println("true"); else System.out.println("false"); } public static void openFor(int[][] nums,boolean[] isOpen,int index){ if(isOpen[index]==true){ for (int j = 0; j < nums[index].length;j++) { if(isOpen[nums[index][j]]==false){ isOpen[nums[index][j]] = true;//打开 openFor(nums, isOpen, nums[index][j]); } } } }
第二题 暴力80%
public static void main(String[] args) { Scanner sc = new Scanner(System.in); int num = sc.nextInt(); int count=0; for (int i = 25; i <=num; i++) { String str = String.valueOf(i); for (int j = 0; j < str.length()-1; j++) { if(str.charAt(j)=='2'&&str.charAt(j+1)=='5'){ count++; break; } } } System.out.println(count); }第三题题目太长了 没做了