Skip to content

Commit 65d1f63

Browse files
committed
[Silver V] Title: 그룹 단어 체커, Time: 108 ms, Memory: 14428 KB -BaekjoonHub
1 parent c7992e2 commit 65d1f63

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# [Silver V] 그룹 단어 체커 - 1316
2+
3+
[문제 링크](https://www.acmicpc.net/problem/1316)
4+
5+
### 성능 요약
6+
7+
메모리: 14428 KB, 시간: 108 ms
8+
9+
### 분류
10+
11+
구현, 문자열
12+
13+
### 제출 일자
14+
15+
2025년 3월 20일 23:30:08
16+
17+
### 문제 설명
18+
19+
<p>그룹 단어란 단어에 존재하는 모든 문자에 대해서, 각 문자가 연속해서 나타나는 경우만을 말한다. 예를 들면, ccazzzzbb는 c, a, z, b가 모두 연속해서 나타나고, kin도 k, i, n이 연속해서 나타나기 때문에 그룹 단어이지만, aabbbccb는 b가 떨어져서 나타나기 때문에 그룹 단어가 아니다.</p>
20+
21+
<p>단어 N개를 입력으로 받아 그룹 단어의 개수를 출력하는 프로그램을 작성하시오.</p>
22+
23+
### 입력
24+
25+
<p>첫째 줄에 단어의 개수 N이 들어온다. N은 100보다 작거나 같은 자연수이다. 둘째 줄부터 N개의 줄에 단어가 들어온다. 단어는 알파벳 소문자로만 되어있고 중복되지 않으며, 길이는 최대 100이다.</p>
26+
27+
### 출력
28+
29+
<p>첫째 줄에 그룹 단어의 개수를 출력한다.</p>
30+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
public static void main(String[] args) throws IOException {
7+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
9+
long count = br.lines()
10+
.skip(1)
11+
.filter(l -> {
12+
Set<Character> set = new HashSet<>();
13+
char tc = ' ';
14+
for (char ch : l.toCharArray()) {
15+
if (ch != tc && set.contains(ch)) {
16+
return false;
17+
}
18+
set.add(ch);
19+
tc = ch;
20+
}
21+
return true;
22+
}).count();
23+
24+
bw.write(String.valueOf(count));
25+
bw.flush();
26+
bw.close();
27+
br.close();
28+
}
29+
}

0 commit comments

Comments
 (0)