https://www.acmicpc.net/problem/11005
11005번: 진법 변환 2
10진법 수 N이 주어진다. 이 수를 B진법으로 바꿔 출력하는 프로그램을 작성하시오. 10진법을 넘어가는 진법은 숫자로 표시할 수 없는 자리가 있다. 이런 경우에는 다음과 같이 알파벳 대문자를
www.acmicpc.net
import java.util.*;
import java.io.*;
public class Main
{
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
String[] input = br.readLine().split(" ");
int n = Integer.valueOf(input[0]);
int b = Integer.valueOf(input[1]);
bw.write(Integer.toString(n,b).toUpperCase());
bw.flush();
}
}
라이브러리를 안쓰고 푸는법
import java.util.Scanner;
class Main
{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int B = sc.nextInt();
String ans = "";
while (N > 0) {
int digit = N % B;
if (digit < 10) ans += digit;
else ans += (char)('A' + digit - 10);
N /= B;
}
System.out.println(new StringBuilder(ans).reverse());
}
}
유사문제
https://yunzae.tistory.com/318
자바 문법 - 진수 바꾸기 (3진법뒤집기)
https://school.programmers.co.kr/learn/courses/30/lessons/68935 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는
yunzae.tistory.com
'Problem Solving > 구현' 카테고리의 다른 글
BOJ3085 사탕 게임 (1) | 2024.01.30 |
---|---|
BOJ11068 회문인수 (1) | 2024.01.30 |
BOJ10448 유레카이론* (1) | 2024.01.30 |
BOJ3273 두 수의 합* (1) | 2024.01.29 |
BOJ10989 수 정렬하기3 (1) | 2024.01.29 |
https://www.acmicpc.net/problem/11005
11005번: 진법 변환 2
10진법 수 N이 주어진다. 이 수를 B진법으로 바꿔 출력하는 프로그램을 작성하시오. 10진법을 넘어가는 진법은 숫자로 표시할 수 없는 자리가 있다. 이런 경우에는 다음과 같이 알파벳 대문자를
www.acmicpc.net
import java.util.*;
import java.io.*;
public class Main
{
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
String[] input = br.readLine().split(" ");
int n = Integer.valueOf(input[0]);
int b = Integer.valueOf(input[1]);
bw.write(Integer.toString(n,b).toUpperCase());
bw.flush();
}
}
라이브러리를 안쓰고 푸는법
import java.util.Scanner;
class Main
{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int B = sc.nextInt();
String ans = "";
while (N > 0) {
int digit = N % B;
if (digit < 10) ans += digit;
else ans += (char)('A' + digit - 10);
N /= B;
}
System.out.println(new StringBuilder(ans).reverse());
}
}
유사문제
https://yunzae.tistory.com/318
자바 문법 - 진수 바꾸기 (3진법뒤집기)
https://school.programmers.co.kr/learn/courses/30/lessons/68935 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는
yunzae.tistory.com
'Problem Solving > 구현' 카테고리의 다른 글
BOJ3085 사탕 게임 (1) | 2024.01.30 |
---|---|
BOJ11068 회문인수 (1) | 2024.01.30 |
BOJ10448 유레카이론* (1) | 2024.01.30 |
BOJ3273 두 수의 합* (1) | 2024.01.29 |
BOJ10989 수 정렬하기3 (1) | 2024.01.29 |