본문 바로가기

백준

4659)비밀번호 발음하기

https://www.acmicpc.net/problem/4659


주어진 입력이 3 가지 제약 조건을 지키는 지 확인하는 문제다.


제약 조건이 어떻게 구현되는가를 연습해볼 수 있었다.


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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include<stdio.h>
#include<string.h>
#define TRUE 1
#define FALSE 0
 
int isVowel(char c) {
    int isVowel = FALSE;
    switch (c)
    {
    case 'a':
        isVowel = TRUE;
        break;
    case 'e':
        isVowel = TRUE;
        break;
    case 'i':
        isVowel = TRUE;
        break;
    case 'o':
        isVowel = TRUE;
        break;
    case 'u':
        isVowel = TRUE;
        break;
    }
    return isVowel;
}
 
char isContinue(char *S) {
    int count = 0;
 
    for (int i = 0; S[i] != NULL; i++) {
        if (S[i] == S[i + 1&& S[i] != 'e' && S[i] != 'o') count++;
    }
}
 
int main() {
    char password[21];
    int cntVowel = 0;
    int cntVowelContinue = 0;
    int cntConsonantContinue = 0;
    int isComply1 = TRUE, isComply2 = TRUE, isComply3 = TRUE;
 
    while (TRUE) {
        scanf("%s", password);
        if (strcmp(password, "end"== 0break;
        for (int i = 0; password[i] != NULL; i++) {
 
            if (isVowel(password[i])) { //모음일 때
                cntVowel++;
                cntVowelContinue++;
                cntConsonantContinue = 0;
            }
            else { //자음일 때
                cntConsonantContinue++;
                cntVowelContinue = 0;
 
            }
            //제약 2 : 모음이 3개 혹은 자음이 3개 연속으로 오면 안된다.
            if (cntConsonantContinue >= 3 || cntVowelContinue >= 3) {
                isComply2 = FALSE; break;
            }
 
            //제약 3 : 같은 글자가 연속적으로 두번 오면 안되나, ee 와 oo는 허용한다.
            if (password[i] == password[i + 1&& password[i] != 'e' && password[i] != 'o') {
                isComply3 = FALSE; break;
            }
        }
        //제약 1 : 모음(a,e,i,o,u) 하나를 반드시 포함하여야 한다.
        if (cntVowel == 0) isComply1 = FALSE;
 
        if (isComply1 && isComply2 && isComply3) printf("<%s> is acceptable.\n", password);
        else printf("<%s> is not acceptable.\n", password);
 
        isComply1 = TRUE; isComply2 = TRUE; isComply3 = TRUE;
        cntVowel = 0; cntConsonantContinue = 0; cntVowelContinue = 0;
    }
 
    return 0;
}
cs


'백준' 카테고리의 다른 글

10798)세로읽기  (0) 2019.02.02
6376)e 계산  (0) 2019.02.02
3460)이진수  (0) 2019.02.01
2799)블라인드  (0) 2019.01.31
2822)점수 계산  (0) 2019.01.31