Skip to content

Commit 5474f31

Browse files
authored
[20250317] BOJ / G4 / 1과 5 / 권혁준
1 parent d52aac7 commit 5474f31

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
```java
2+
3+
import java.util.*;
4+
import java.io.*;
5+
6+
class Main {
7+
8+
// IO field
9+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
10+
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
11+
static StringTokenizer st = new StringTokenizer("");
12+
13+
static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());}
14+
static int nextInt() throws Exception {
15+
if(!st.hasMoreTokens()) nextLine();
16+
return Integer.parseInt(st.nextToken());
17+
}
18+
static long nextLong() throws Exception {
19+
if(!st.hasMoreTokens()) nextLine();
20+
return Long.parseLong(st.nextToken());
21+
}
22+
static void bwEnd() throws Exception {bw.flush();bw.close();}
23+
24+
// Additional field
25+
26+
static int T;
27+
static char[] N;
28+
29+
public static void main(String[] args) throws Exception {
30+
31+
T = nextInt();
32+
while(T-->0) {
33+
34+
ready();
35+
solve();
36+
}
37+
38+
bwEnd();
39+
40+
}
41+
42+
static void ready() throws Exception{
43+
44+
N = br.readLine().toCharArray();
45+
46+
}
47+
48+
static void solve() throws Exception{
49+
50+
if(N[N.length-1] == '5') bw.write("0 5\n");
51+
else {
52+
int sum = 0, pos1 = 0, pos5 = -1;
53+
for(int i=0;i<N.length;i++) {
54+
sum += N[i]-'0';
55+
if(N[i] == '1') pos1 = i;
56+
else pos5 = i;
57+
}
58+
if(sum%3 == 0) bw.write("0 3\n");
59+
else if(sum%3 == 1) bw.write(++pos1 + " 3\n");
60+
else {
61+
if(pos5 == -1) {
62+
if(sum%2 == 0) bw.write("0 11\n");
63+
else bw.write("1 11\n");
64+
}
65+
else bw.write(++pos5 + " 3\n");
66+
}
67+
}
68+
69+
}
70+
71+
}
72+
73+
```

0 commit comments

Comments
 (0)