您的位置:首页 > 编程语言

牛客网编程练习之编程马拉松:寻找舞伴

2017-12-13 01:34 183 查看

 

标记一下即可,只是记得需要区分男生和女生,虽然同性才是真爱...

 

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);
}

}

}

 

题目来源: https://www.nowcoder.com/practice/33b1a1a460914456ae2b3afb16f095af?tpId=3&tqId=10902&tPage=1&rp=&ru=/ta/hackathon&qru=/ta/hackathon/question-ranking

 

.

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: