*solved.ac 기준 실버 5단계 문제
풀이)
스택을 이용해 풀 수 있는 문제이다.
단어가 그룹단어일지 아닐지 판별하는 불린형 변수 flag를 선언해준다.
내 코드)
import java.util.Stack;
import java.io.*;
public class Backjoon1316 {
public static void main(String[]args) throws IOException{
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(bf.readLine());
int count = 0;
for(int i=0 ; i<T ; i++) {
Stack<Character> stack = new Stack<Character>();
boolean flag = true;
char[]input = bf.readLine().toCharArray();
if(input.length==1) {
count++;
continue;
}
for(int j=0 ; j<input.length ; j++) {
if(stack.empty()) {
stack.push(input[j]);
continue;}
if(input[j] == stack.peek()) {
continue;
}
if(stack.contains(input[j])) {
flag = false;
break;
}else {
stack.push(input[j]);
}
}
if(flag)
count++;
}
System.out.println(count);
}
}