1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| import java.util.Scanner;
public class HAMMINGCODE {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int cases = sc.nextInt();
while (cases-- > 0) {
String sInput = sc.next();
char[] cInput = sInput.toCharArray();
int iParity = (cInput[0]^cInput[2]^cInput[4]^cInput[6])*1+(cInput[1]^cInput[2]^cInput[5]^cInput[6])*2+(cInput[3]^cInput[4]^cInput[5]^cInput[6])*4;
if(iParity != 0){
cInput[iParity-1] = cInput[iParity-1]=='0'?'1':'0';
}
char[] output = new char[]{cInput[2],cInput[4],cInput[5],cInput[6]};
System.out.println(output);
}
}
}
|
댓글 없음:
댓글 쓰기