流式编程:排序+双指针,依次发糖果
import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args){ Scanner scanner = new Scanner(System.in); String[] s1 = scanner.nextLine().split(" "); String[] s2 = scanner.nextLine().split(" "); int[] kid = Arrays.stream(s1).mapToInt(Integer::parseInt).sorted().toArray(); int[] suger = Arrays.stream(s2).mapToInt(Integer::parseInt).sorted().toArray();//suger>=kid int p = 0, q = 0, cnt = 0; while (p < kid.length && q < suger.length) { if(kid[p] <= suger[q]){ cnt++; p++; q++; }else{ q++; } } System.out.println(cnt); } }