백준 1316번: 그룹 단어 체커
1. 문제 설명
2. 문제 풀이
- 단어의 갯수를 입력받는다.
- 문자열로 단어를 입력받는다.
- 단어를 이루고 있는 알파벳을 검사해준다.
코드
import java.util.*;
public class No_1316 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int N=sc.nextInt();
int count=N;
for(int i=0;i<N;i++) {
String str= sc.next();
boolean[] check=new boolean[26];
for(int j=0;j<str.length()-1;j++) {
if(str.charAt(j)!=str.charAt(j+1)) {
if(check[str.charAt(j+1)-'a']==true) {
count--;
break;
}
}
check[str.charAt(j)-'a']=true;
}
}
System.out.println(count);
}
}
실행 결과