Problem Solving/Baekjoon
[백준] 20170 Commemorative Dice - Brute Force / Java
graycode
2023. 10. 30. 19:23
• 문제 링크
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;
}
}