Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- Binary Tree
- Tree
- 구현
- Math
- Method
- sorting
- hash table
- Data Structure
- implement
- 코테
- two pointers
- database
- simulation
- SQL
- geometry
- Counting
- greedy
- dynamic programming
- java
- array
- Matrix
- 파이썬
- Number Theory
- string
- Stack
- 코딩테스트
- 자바
- Class
- bit manipulation
- Binary Search
Archives
- Today
- Total
코린이의 소소한 공부노트
[백준 온라인 저지] 2745. 진법 변환 본문
- 입력: 첫째 줄에 N과 B가 주어진다. (2 ≤ B ≤ 36) B진법 수 N을 10진법으로 바꾸면, 항상 10억보다 작거나 같다.
- 출력: 첫째 줄에 B진법 수 N을 10진법으로 출력한다.
import java.util.*;
import java.io.*;
class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer token = new StringTokenizer(br.readLine());
String num = token.nextToken();
int b = Integer.parseInt(token.nextToken()), answer = 0;
for(int i=0 ; i<num.length() ; i++){
char c = num.charAt(i);
if(c<='9')
answer += (c-'0')*(int)Math.pow(b,num.length()-i-1);
else
answer += (c-'A'+10)*(int)Math.pow(b,num.length()-i-1);
}
System.out.println(answer);
}
}
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[백준 온라인 저지] 2720. 세탁소 사장 동혁 (0) | 2023.04.04 |
---|---|
[백준 온라인 저지] 11005. 진법 변환 2 (0) | 2023.04.03 |
[LeetCode/Easy] 989. Add to Array-Form of Integer (0) | 2023.04.03 |
[LeetCode/Easy] 933. Number of Recent Calls (0) | 2023.03.31 |
[LeetCode/Easy] 917. Reverse Only Letters (0) | 2023.03.31 |