반응형
📖 문제

📃 코드
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static int parseDigit(String N, int digit) {
int temp = 1;
int ans = 0;
for (int i = N.length() - 1; i >= 0; i--) {
char c = N.charAt(i);
if ('A' <= c && 'Z' >= c) {
// B - A = 1, 1 + 10(over Decimal), temp = digit
ans += (c - 'A' + 10) * temp;
} else {
ans += (c - '0') * temp;
}
temp *= digit;
}
return ans;
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s[] = br.readLine().split(" ");
String N = s[0];
int digit = Integer.parseInt(s[1]); //digit
int result = parseDigit(N, digit);
System.out.println(result);
}
}
🔗 링크
https://www.acmicpc.net/problem/2745
2745번: 진법 변환
B진법 수 N이 주어진다. 이 수를 10진법으로 바꿔 출력하는 프로그램을 작성하시오. 10진법을 넘어가는 진법은 숫자로 표시할 수 없는 자리가 있다. 이런 경우에는 다음과 같이 알파벳 대문자를
www.acmicpc.net
'Study & Project ✏️ > 알고리즘 📋' 카테고리의 다른 글
| 백준[JAVA] 10989.수 정렬하기 3- 자바 (0) | 2022.09.15 |
|---|---|
| 백준[JAVA] 9251.LCS - 자바 (0) | 2022.09.15 |
| 백준[JAVA] 2750.수 정렬하기 - 자바 (0) | 2022.09.12 |
| 백준[JAVA] 2355.시그마 - 자바 (0) | 2022.09.11 |
| 백준[JAVA] 2292.벌집 - 자바 (0) | 2022.09.11 |