티스토리 뷰

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

 

import java.io.*;
import java.util.StringTokenizer;

class Solution {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();

        int T = Integer.parseInt(br.readLine());
        for (int t = 1; t <= T; t++) {
            StringTokenizer st = new StringTokenizer(br.readLine());

            int s = Integer.parseInt(st.nextToken());
            int e = Integer.parseInt(st.nextToken());

            int cnt = 0;
            for (int i = s; i <= e; i++) {
                double sqrt = Math.sqrt(i);
                if (sqrt % 1 != 0) {
                    continue;
                }

                if (isPalindrome(i) && isPalindrome((int) sqrt)) {
                    cnt++;
                }
            }

            sb.append("#" + t + " " + cnt + "\n");
        }

        System.out.println(sb);
    }

    static boolean isPalindrome(int num) {
        String str = String.valueOf(num);
        int mid = str.length() / 2;

        for (int i = 0; i < mid; i++) {
            if (str.charAt(i) != str.charAt(str.length() - (i + 1))) {
                return false;
            }
        }

        return true;
    }
}
Total
Today
Yesterday
최근에 올라온 글
«   2024/11   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30