• 문제 링크
13410번: 거꾸로 구구단
일반적인 구구단에서 가장 큰 수는 마지막 항의 값이 제일 크다. 거꾸로 구구단에서는, 각 항에 구구단의 계산 결과로 나온 값을 뒤집어 저장을 한다. 이렇게 하면 가장 큰 값이 항상 마지막이
www.acmicpc.net
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
public class Main {
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int n = read(), k = read(), max = n;
while (k > 2) max = Math.max(max, reverse(n * k--));
bw.write(String.valueOf(max));
bw.flush();
}
private static int reverse(int src) {
int tgt = 0;
do tgt = tgt * 10 + src % 10; while ((src /= 10) > 0);
return tgt;
}
private static int read() throws IOException {
int c, n = System.in.read() & 15;
while ((c = System.in.read()) > 32) n = (n << 3) + (n << 1) + (c & 15);
return n;
}
}
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
public class Main {
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int n = read(), k = read(), max = n;
while (k > 2)
max = Math.max(max, Integer.parseInt(new StringBuilder((String.valueOf(n * k--))).reverse().toString()));
bw.write(String.valueOf(max));
bw.flush();
}
private static int read() throws IOException {
int c, n = System.in.read() & 15;
while ((c = System.in.read()) > 32) n = (n << 3) + (n << 1) + (c & 15);
return n;
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 17173 배수들의 합 - Brute Force / Java (0) | 2023.12.29 |
---|---|
[백준] 2399 거리의 합 - Brute Force / Java (0) | 2023.12.28 |
[백준] 1773 폭죽쇼 - Brute Force / Java (0) | 2023.12.26 |
[백준] 1233 주사위 - Brute Force / Java (0) | 2023.12.25 |
[백준] 14697 방 배정하기 - Brute Force / Java (0) | 2023.12.24 |
댓글