Problem Solving/Baekjoon
[백준] 3279 DOLLARS - Greedy / Java
graycode
2025. 8. 26. 17:19
• 문제 링크
https://www.acmicpc.net/problem/3279
• 풀이 코드
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();
float sum = 100, i = read();
while (n-- > 1) {
float j = read();
if (i > j) sum *= i / j;
i = j;
}
bw.write(String.format("%.2f", sum));
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;
}
}