[SWEA] 1225 암호 생성기

Time Lapse :10min 2sec

1225.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import java.io.*;
import java.util.*;

public class Solution {
public static int[] arr = new int[8];

public static void main(String[] args) throws Exception {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int T = 10, tc = 1, minVal;
while (T-- != 0) {
bf.readLine();
minVal = Integer.MAX_VALUE;
StringTokenizer st = new StringTokenizer(bf.readLine());
for (int i = 0; i < 8; ++i) {
minVal = Math.min(minVal, (arr[i] = fastParseInt(st.nextToken())));
}
minVal = minVal - (minVal % 15) - 15;
for (int i = 0; i < 8; ++i) {
arr[i] -= minVal;
}
boolean flag = true;
int idx = 0;
while (flag) {
for (int i = 1; flag && i <= 5; ++i, idx = (idx + 1) % 8) {
arr[idx] -= i;
if (arr[idx] <= 0) {
flag = false;
arr[idx] = 0;
}
}
}
bw.write("#" + tc++ + " ");
for (int i = 0; i < 8; ++i, idx = (idx + 1) % 8)
bw.write(arr[idx] + " ");
bw.write("\n");
}
bw.flush();
}

public static int fastParseInt(String str) {
int ret = 0;
for (int i = 0; i < str.length(); ++i)
ret = (ret << 3) + (ret << 1) + (str.charAt(i) & 0b1111);
return ret;
}
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/08/04/PS/SWEA/1225/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.