Skip to content

Commit 38e9bf9

Browse files
committed
CT_89
1 parent 81b9887 commit 38e9bf9

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package S5;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
7+
public class Boj_32281_유리구슬GlassBead {
8+
public static void main(String[] args) throws IOException {
9+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
10+
11+
int N = Integer.parseInt(br.readLine());
12+
String str = br.readLine();
13+
14+
long result = 0;
15+
long cnt = 0;
16+
17+
for (int i = 0; i < N; i++) {
18+
if (str.charAt(i) == '1') {
19+
cnt++;
20+
} else {
21+
result += cnt * (cnt + 1) / 2;
22+
cnt = 0;
23+
}
24+
}
25+
result += cnt * (cnt + 1) / 2;
26+
27+
System.out.print(result);
28+
}
29+
}
30+
31+
32+
33+
34+
35+
/*
36+
37+
38+
0 0 0 0 0
39+
0 0 0 1 0 0
40+
1 0 0 1 1 0 0
41+
1 1 0 1 1 1 0 1
42+
43+
*/

0 commit comments

Comments
 (0)