Repository navigation
Expand file tree
/
Copy pathBOJ_1316.java
More file actions
55 lines (46 loc) · 1.45 KB
/
Copy pathBOJ_1316.java
File metadata and controls
55 lines (46 loc) · 1.45 KB
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
48
49
50
51
52
53
54
55
package baekjoon.silver;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;
public class BOJ_1316 {
public static int count = 0;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//입력
int lineNumber = Integer.parseInt(br.readLine());
String word[] = new String[lineNumber];
for (int i = 0; i < lineNumber; i++) {
word[i] = br.readLine();
}
//정답
for (int i = 0; i < word.length; i++) {
Stack<Character> stacks = new Stack<>();
int j;
point1 : for (j = 0; j < word[i].length(); j++) {
char c = word[i].charAt(j);
if (stacks.isEmpty()) {
stacks.push(c);
}
else {
if(stacks.peek().equals(c)) {
continue;
}
else {
if(stacks.search(c) != -1) {
break point1;
}
else {
stacks.push(c);
}
}
}
}
if(j == word[i].length()) {
count++;
}
}
//출력
System.out.println(count);
}
}