개요[ | ]
- HR자바 Java BitSet
Java
Copy
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
BitSet[] B = new BitSet[2];
B[0] = new BitSet(N);
B[1] = new BitSet(N);
int M = sc.nextInt();
for(int i=0; i<M; i++) {
String operation = sc.next();
int x = sc.nextInt();
int y = sc.nextInt();
switch( operation ) {
case "AND": B[x-1].and(B[y-1]); break;
case "OR": B[x-1].or(B[y-1]); break;
case "XOR": B[x-1].xor(B[y-1]); break;
case "FLIP": B[x-1].flip(y); break;
case "SET": B[x-1].set(y); break;
}
System.out.println( B[0].cardinality()+" "+B[1].cardinality() );
}
}
}
편집자 Jmnote Jmnote bot
로그인하시면 댓글을 쓸 수 있습니다.