标记一下即可,只是记得需要区分男生和女生,虽然同性才是真爱...
AC代码:
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
/**
* @author CC11001100
*/
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNextInt()) {
int ans = 0;
int n = sc.nextInt();
int m = sc.nextInt();
Map<Integer, Integer> count = new HashMap<>();
while (n-- > 0) {
int t = sc.nextInt();
count.put(t, count.getOrDefault(t, 0) + 1);
}
while (m-- > 0) {
int t = sc.nextInt();
int k = count.getOrDefault(t, 0);
if (k > 0) {
ans++;
count.put(t, k - 1);
}
}
System.out.println(ans);
}
}
}
.