Problem details

https://codeforces.com/contest/1956/problem/B

Problem - B - Codeforces

codeforces.com

 

Ideas

  1. You can only score points if you have two cards of the same number.

 

Answer code (Java)

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int t, n, a, ans;
		
		boolean[] checkArr;
		
		t = sc.nextInt();
		for (int i = 0; i < t; i++) {
			n = sc.nextInt();
			
			ans = 0;
			checkArr = new boolean[200000 + 1];
			for (int j = 0; j < n; j++) {
				a = sc.nextInt();
				if (checkArr[a]) { // You can only score points if you have two cards of the same number.
					ans++;
					continue;
				}
				checkArr[a] = true;
			}
			System.out.println(ans);
		}
	}
}

 

+ Recent posts