✔나의 답-> 맞음
import java.util.*;
public class p2_3 {
public static String[] solution(int n, int[] A, int[] B){
String[] arr= new String[n];
for(int i=0;i<n;i++){
if(Math.abs(A[i]-B[i])==1){
if(A[i]>B[i]) arr[i]="A";
else arr[i]="B";
}
else if (A[i]==B[i]) arr[i]="D";
else {
if( A[i]==3) arr[i]="B";
else arr[i]="A";
}
}
return arr;
}
public static void main(String[] args){
Scanner kb = new Scanner(System.in);
int n = kb.nextInt();
int[] A= new int[n];
int[] B= new int[n];
for(int i=0;i<n;i++) A[i]=kb.nextInt();
for(int j=0;j<n;j++) B[j]=kb.nextInt();
for(String x : solution(n,A,B)){
System.out.println(x);
}
}
}
✔️ 강의 답
import java.util.*;
public class P2_3 {
public static String solution(int n, int[] a, int[] b){
String answer="";
for(int i=0;i<n;i++){
if(a[i]==b[i]) answer+="D";
else if (a[i]==1 && b[i]==3) answer+="A";
else if (a[i]==2 && b[i]==1) answer+="A";
else if (a[i]==3 && b[i]==2) answer+="A";
else answer+="B";
}
return answer;
}
public static void main(String[] args){
Scanner kb = new Scanner(System.in);
int n = kb.nextInt();
int[] A= new int[n];
int[] B= new int[n];
for(int i=0;i<n;i++) A[i]=kb.nextInt();
for(int j=0;j<n;j++) B[j]=kb.nextInt();
for(char x : solution(n,A,B).toCharArray()){
System.out.println(x);
}
}
}