• 문제 링크
20170번: Commemorative Dice
Since the year 2000, an ICPC regional contest has been held every year in Korea. To commemorate the 21st regional contest this year, it is decided to make a dice. The commemorative dice is a regular cube with a positive number written on each of its sides
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));
StringBuilder sb = new StringBuilder();
int[] a = new int[6], b = new int[6];
for (int i = 0; i < 6; i++) a[i] = read();
for (int i = 0; i < 6; i++) b[i] = read();
int cnt = 0;
for (int i : a) for (int j : b) if (i > j) cnt++;
int gcd = gcd(36, cnt);
sb.append(cnt / gcd).append("/").append(36 / gcd);
bw.write(sb.toString());
bw.flush();
}
private static int gcd(int a, int b) {
return b == 0 ? a : gcd(b, a % b);
}
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' 카테고리의 다른 글
[백준] 9728 Pair Sum - Data Structure / Java (0) | 2023.11.01 |
---|---|
[백준] 13211 Passport Checking - Data Structure / Java (0) | 2023.10.31 |
[백준] 20651 Daisy Chains - Brute Force / Java (0) | 2023.10.29 |
[백준] 1487 물건 팔기 - Brute Force / Java (0) | 2023.10.28 |
[백준] 9881 Ski Course Design - Brute Force / Java (0) | 2023.10.27 |
댓글