백준 1862

hong030·2023년 3월 11일
0
  • 실버 5단계 문제

풀이)
일종의 9진법이다.
9진법을 10진법으로 표현한다고 생각하면 된다.
단, 4를 표현하지 않으므로 자릿수가 4미만인지, 초과인지를 따져서 계산하면 된다.

내 코드)

import java.io.*;

public class Backjoon1862 {
	public static void main(String[]args) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		int N = Integer.parseInt(bf.readLine());
		
		int len = Integer.toString(N).length();
		int ans = 0;
		
		for(int i=0;i<len;i++) {
			int digit = N%10;
			N = N/10;
			
			if(digit>4)
				ans += (digit-1)*Math.pow(9,i);
			else
				ans += digit*Math.pow(9, i);
		}
		System.out.println(ans);
		//*/
	}
}

profile
자바 주력, 프론트 공부 중인 초보 개발자. / https://github.com/hongjaewonP

0개의 댓글