MapleStory Cookie With Halo

πŸ•Έ Algorithm/πŸ•Έ λ°±μ€€ BaekJoon

[λ°±μ€€][java][11005][진법 λ³€ν™˜ 2]

뉴이 NUEY 2024. 3. 13. 01:39
λ°˜μ‘ν˜•

 

import java.util.Scanner;

// 	11005	진법 λ³€ν™˜ 2
public class Main {

    public static void main(String[] args) {
        Scanner in  = new Scanner(System.in);

        int n = in.nextInt();   // 10진법 수
        int b = in.nextInt();   // 진법
        in.close();

        StringBuilder sb = new StringBuilder();

        while (n != 0) {
            int last = n % b;

            String res = "";

            if (last >= 10 ) {
                char c = (char) ((int) last + 55);
                res = Character.toString(c);
            }
            else {
                res = Integer.toString(last);
            }
            
            n /= b;

            sb.append(res);
        }
        System.out.print(sb.reverse().toString());
    }
}
  • 수 % μ§„λ²•μ˜ λ‚˜λ¨Έμ§€ 값을 10μ§„μˆ˜λ‘œ ν‘œν˜„ν•˜λŠ”λ°
  • μ΄λ•Œ λ‚˜λ¨Έμ§€ 값이 0~9의 수. 10μ§„μˆ˜μ΄λ©΄ κ·ΈλŒ€λ‘œ 좜λ ₯
  • μ•„λ‹ˆλ©΄ +55(Ascillμ½”λ“œμ—μ„œ 'A'κ°’)λ₯Ό 더해 char둜 ν˜•λ³€ν™˜ ν›„ 좜λ ₯
  • 좜λ ₯μ‹œ λ¬Έμžμ—΄μ„ λ°˜μ „μ‹œμΌœ 내보내면 λ©λ‹ˆλ‹€.
λ°˜μ‘ν˜•