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

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

 

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

 

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

 

.

相关文章:

  • 2021-09-03
  • 2021-09-23
  • 2021-07-28
  • 2021-07-25
  • 2021-04-04
  • 2021-05-16
  • 2021-06-26
  • 2021-06-14
猜你喜欢
  • 2021-07-13
  • 2021-10-10
  • 2022-12-23
  • 2021-11-17
  • 2021-05-30
  • 2021-06-07
  • 2021-09-25
相关资源
相似解决方案