-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path_1316.java
More file actions
54 lines (48 loc) ยท 1.18 KB
/
_1316.java
File metadata and controls
54 lines (48 loc) ยท 1.18 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
package backjoon;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
// https://www.acmicpc.net/problem/1316
// ๊ทธ๋ฃน ๋จ์ด ์ฒด์ปค
public class _1316 {
// memory 11488 runtime 80
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args) throws IOException {
int cnt = 0;
int numberOfwords = Integer.parseInt(br.readLine());
for (int i = 0; i < numberOfwords; i++) {
if (check()) {
cnt++;
}
}
System.out.print(cnt);
}
static boolean check() throws IOException{
// ๊ฐ ์์๋ ์ํ๋ฒณ์ ๋ํ๋ด๋ ๋ถ๋ฆฌ์ธ ๋ฐฐ์ด๋ก, ์ํ๋ฒณ์ด ๋์จ์ ์๋์ง ์ ๋ฌด๋ง ํ์ธํ๋ฉด ๋๊ธฐ๋๋ฌธ์ booleanํ์
์ผ๋ก ์ค์ ํ๋ค.
boolean[] check = new boolean[26];
int prev = 0;
String str = br.readLine();
for(int i = 0; i < str.length(); i++) {
int now = str.charAt(i);
if (prev != now) {
if (!check[now - 'a']) {
check[now - 'a'] = true;
prev = now;
}
else {
return false;
}
}
}
return true;
}
}
/*
input
3
happy
new
year
output
3
*/