짬뽕얼큰하게의 맨땅에 헤딩 :: 백준(BOJ) 1316 그룹 단어 체커

이전과 문자가 같을경우와 같지 않을 경우로 나누었다.

같지 않을경우 기존에 문자가 나왔는지 체크한다.


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
#include <cstdio>
int T;
char str[101];
int arr[201];
int main(void){
  int T;
  scanf("%d"&T);
  scanf("%*c");
  int cnt = 0;
  while(T--){
    scanf("%s", str);
 
 
    for(int i = 'a'; i <= 'z'; i++){
      arr[i] = 0;
    }
    arr[str[0]]++;
    bool success = true;
    for(int i = 1 ; success && str[i]; i++){
      if(str[i] == str[i - 1]){
        arr[str[i]]++;
      }
      else{
        if(arr[str[i]] > 0) success = false;
        else arr[str[i]]++;
      }
    }
    if(success) cnt++;
  }
  printf("%d\n", cnt);
 
 
}
 
cs


'알고리즘' 카테고리의 다른 글

알고스팟(algospot) ITES - 외계 신호 분석  (0) 2018.12.05
백준(BOJ) 2581 소수  (0) 2018.11.29
백준(BOJ) 2748 피보나치 수 2  (0) 2018.11.29
비트연산 공부하기  (0) 2018.11.26
비트연산 실수하기 쉬운것들  (0) 2018.11.26
블로그 이미지

짬뽕얼큰하게

,