[softeer] CPTI

https://softeer.ai/app/assessment/index.html?xid=462352&xsrfToken=Ntihlou6S6NLb5pFkIy9Od0zNDdXWmlq&testType=practice

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] people = new int[N];

        for (int i = 0; i < N; i++) {
            String line = sc.next();
            people[i] = Integer.parseInt(line, 2);
        }

        int count = 0;

        for (int i = 0; i < N; i++) {
            for (int j = i+1; j < N; j++) {
                if ( Integer.bitCount(people[i] ^ people[j]) <= 2) {
                    count++;
                }
            }
        }

        System.out.println(count);
    }
}



© 2023 Lee. All rights reserved.