import java.util.*;
public class P2_6{
public static ArrayList<Integer> solution(ArrayList<String> list){
ArrayList<Integer> list_n = new ArrayList<Integer>();
for(String x: list){
StringBuffer sb = new StringBuffer(x);
String str_= sb.reverse().toString();
int str_n =Integer.parseInt(str_);
for(int i=2;i<str_n;i++){
if(str_n%i==0)
break;
if(i==str_n-1){
list_n.add(str_n);
}
}
}
return list_n;
}
public static void main(String[] args){
Scanner kb = new Scanner(System.in);
int N = kb.nextInt();
ArrayList<String> list = new ArrayList<String>();
for(int i=0;i<N;i++){
String input = kb.next();
list.add(input);
}
for(int x : solution(list))
System.out.print(x+" ");
}
}
뭔가 이상함
강의 듣고 힌트 얻어서 다시 푼 결과 -> 성공
import java.util.*;
public class P2_6{
public static boolean isPrime(int n){
if (n==1) return true;
for(int i=2;i<n;i++){
if(n%i==0) return true;
}
return false;
}
public static ArrayList<Integer> solution(int n, ArrayList<Integer> list){
ArrayList<Integer> answer = new ArrayList<>();
for(int i=0;i<n;i++){
int tmp=list.get(i);
int t=0, res=0;
while(tmp!=0){
t=tmp%10;
res=res*10+t;
tmp=tmp/10;
} //while
if(!isPrime(res)) answer.add(res);
}//for
return answer;
}
public static void main(String[] args){
Scanner kb = new Scanner(System.in);
int n = kb. nextInt();
ArrayList<Integer> list =new ArrayList<>();
for(int i=0;i<n;i++){
int input = kb.nextInt();
list.add(input);
}
for(int x : solution(n,list)) System.out.print(x+" ");
}
}