Skip to content

Commit d2477b1

Browse files
authored
[20251012] BOJ / G3 / 그램팬 / 이종환
1 parent 92ea237 commit d2477b1

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

0224LJH/202510/12 BOJ 그램팬.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
```java
2+
import java.io.BufferedReader;
3+
import java.io.IOException;
4+
import java.io.InputStreamReader;
5+
import java.util.*;
6+
7+
public class Main {
8+
9+
static final char START = 'A';
10+
static final char FINAL = 'Z';
11+
static String input;
12+
static long ans;
13+
14+
public static void main(String[] args) throws NumberFormatException, IOException {
15+
init();
16+
process();
17+
print();
18+
}
19+
20+
21+
22+
public static void init() throws NumberFormatException, IOException {
23+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
24+
input = br.readLine();
25+
}
26+
27+
public static void process() throws IOException {
28+
int idx = 0;
29+
int size = input.length();
30+
long cnt = 0;
31+
long serialStart = 0;
32+
33+
while(idx < size -1 ){
34+
if (input.charAt(idx) == START) {
35+
serialStart++;
36+
idx++;
37+
}
38+
else if (input.charAt(idx) == START + 1 && serialStart != 0) {
39+
boolean isGramPen = false;
40+
char target = 'B';
41+
long serialLast = 1;
42+
43+
44+
while(idx < size) {
45+
if (input.charAt(idx) == target) {
46+
if (target == 'Z') serialLast++;
47+
48+
} else if(target != 'Z' && input.charAt(idx) == target+1) {
49+
target++;
50+
if (target == 'Z') isGramPen = true;
51+
} else {
52+
break;
53+
}
54+
idx++;
55+
}
56+
57+
if (isGramPen) cnt += serialStart*serialLast;
58+
serialStart = 0;
59+
} else {
60+
idx++;
61+
serialStart = 0;
62+
}
63+
64+
}
65+
ans = cnt;
66+
}
67+
68+
69+
70+
71+
public static void print() {
72+
System.out.print(ans);
73+
74+
}
75+
}
76+
```

0 commit comments

Comments
 (0)