9.4滴滴笔试
第一题:桃子,没用滑动窗口只过了54。。。求评论区大佬贴个A的代码
第二题:用map收集美丽数A了
import java.util.HashMap; import java.util.Scanner; public class Main { /* 2 0 1 0 10 0 1 */ public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); int[][] nums = new int[2][n]; int min = Integer.MAX_VALUE; int max = Integer.MIN_VALUE; for (int i = 0; i < n; i++) { nums[0][i] = scan.nextInt(); min = Math.min(min,nums[0][i]); } for (int i = 0; i < n; i++) { nums[1][i] = scan.nextInt(); max = Math.max(max,nums[1][i]); } int[] target = new int[n]; for (int i = 0; i < n; i++) { target[i] = scan.nextInt(); } int first = 0; HashMap<Integer,Integer> map = new HashMap<>(); //装美丽值 for (int l =min; l <= max; l++) { if(l<10){ map.put(l,l); continue; } first = l%10; int num = l/10; while(num!=0){ first^=(num%10); num/=10; } map.put(l,first); } int[] ans = new int[n]; for (int i = 0; i < n; i++) { for (int j = nums[0][i]; j <= nums[1][i]; j++) { if(map.get(j)==target[i]){ ans[i]+=1; } } } for (int i = 0; i < n; i++) { System.out.print(ans[i]); System.out.print(" "); } } }