SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
회문 간단하게 구하기
static boolean is_par(String str) {
String tmp = new StringBuilder(str).reverse().toString();
if(str.equalsIgnoreCase(tmp)){
return true;
}
else return false;
}
전체 코드
import java.util.Scanner;
class Solution{
public static void main(String args[]) throws Exception{
Scanner sc = new Scanner(System.in);
int T=sc.nextInt();
for(int test_case = 1; test_case <= T; test_case++) {
boolean arr[]=new boolean[1001];
for(int num=1;num<=35;num++){
if(is_par(String.valueOf(num)) && is_par(String.valueOf(num*num))){
arr[num*num]=true;
}
}
// 3
int A = sc.nextInt();
int B = sc.nextInt();
int cnt = 0;
for (int num = A; num <= B; num++) if (arr[num]) cnt++;
System.out.println("#"+test_case+" "+cnt);
}
}
static boolean is_par(String str) {
String tmp = new StringBuilder(str).reverse().toString();
if(str.equalsIgnoreCase(tmp)){
return true;
}
else return false;
}
}
'알고리즘 > 삼성 SW expert Academy' 카테고리의 다른 글
[SWEA] 9839. 최고의 쌍_JAVA (0) | 2022.05.23 |
---|---|
[SWEA] 10059. 유효기간_JAVA (0) | 2022.05.22 |
[SWEA] 10726. 이진수 표현_JAVA (0) | 2022.05.21 |
[SWEA] 10804. 문자열의 거울상_JAVA (0) | 2022.05.21 |
[SWEA] 11315. 오목 판정_JAVA (0) | 2022.05.20 |