ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 2941 크로아티아 알파벳
    BOJ 2023. 5. 6. 22:42

    문제요약 : 여러 개의 문자를 합한 문자열이 새로운 문자(크로아티아 알파벳)가 된다고 생각하면 된다. 따라서 문자열에 문자를 입력받고 특정 문자열의 개수를 세는 문제이다.

     

    체크포인트 : 위 목록에 없는 알파벳은 한 글자씩 센다. 

     

    풀이 : 배열에 문자열을 입력받고 배열의 원소들을 확인하여 크로아티아 알파벳을 변경해서 입력한 것인지 아닌지를 일일이 확인한다.

     

    팁 : 단순히 if문 여러 개와 &&연산자로 구현해도 되지만 (코드 1) 크로아티아 알파벳이 6개이고 첫 문자가 겹치는게 몇 가지 있기 때문에 케이스를 조금 좁혀서 나눠도 괜찮을 것 같다. (코드 2)

    코드 1

    #include <bits/stdc++.h>
    using namespace std;
    int main() {
    char words[101];
    int i = 0;
    int cnt = 0;
    scanf("%s", words);
    for(i = 0; i < strlen(words); i++){
    int check = 0;
    if(words[i] == 'c'&& words[i+1] == '=') {
    cnt++;
    i++;
    check++;
    }
    if(words[i] == 'c'&& words[i+1] == '-') {
    cnt++;
    i++;
    check++;
    }
    if(words[i] == 'd'&& words[i+1] == 'z' && words[i+2] == '=') {
    cnt++;
    i += 2;
    check++;
    }
    if(words[i] == 'd'&& words[i+1] == '-') {
    cnt++;
    i++;
    check++;
    }
    if(words[i] == 'l'&& words[i+1] == 'j') {
    cnt++;
    i++;
    check++;
    }
    if(words[i] == 'n'&& words[i+1] == 'j') {
    cnt++;
    i++;
    check++;
    }
    if(words[i] == 's'&& words[i+1] == '=') {
    cnt++;
    i++;
    check++;
    }
    if(words[i] == 'z'&& words[i+1] == '=') {
    cnt++;
    
    
    i++;
    check++;
    }
    if(check == 0) cnt++;
    }
    printf("%d", cnt);
    return 0;
    }
    } // 이 코드는 풀이용 코드라고 생각하자.

     

    코드 2

    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
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    #include <bits/stdc++.h>
    using namespace std;
     
    int main() {
        char words[101];
        int i = 0;
        int cnt = 0;
        scanf("%s", words);
     
        for(i = 0; i < strlen(words); i++){
            int check = 0;
            if(words[i] == 'c'&& words[i+1== '=') {
                cnt++;
                i++;
                check++;
            }
            if(words[i] == 'c'&& words[i+1== '-') {
                cnt++;
                i++;
                check++;
            }
            if(words[i] == 'd'&& words[i+1== 'z' && words[i+2== '=') {
                cnt++;
                i += 2;
                check++;
            }
            if(words[i] == 'd'&& words[i+1== '-') {
                cnt++;
                i++;
                check++;
            }
            if(words[i] == 'l'&& words[i+1== 'j') {
                cnt++;
                i++;
                check++;
            }
            if(words[i] == 'n'&& words[i+1== 'j') {
                cnt++;
                i++;
                check++;
            }
            if(words[i] == 's'&& words[i+1== '=') {
                cnt++;
                i++;
                check++;
            }
            if(words[i] == 'z'&& words[i+1== '=') {
                cnt++;
                i++;
                check++;
            }
            if(check == 0) cnt++;
        }
        printf("%d", cnt);
        return 0;
    }
    #include <bits/stdc++.h>
    #include <string>
    using namespace std;
     
    int n;
    int i = 666;
    int cnt = 0;
    int check = 0;
    string s;
    string arr[10001];
     
    int main() {
        cin >> n;
        
        while(1){
            s = to_string(i);
            for(int j = 0; j < s.length();j++){
                if(s[j] == s[j+1== s[j+2== '6'){
                    arr[cnt] = s;
                    check = 1;
                }
                if(check == 1){
                    cnt++;
                    check = 0;
                }
                i++;
                if(cnt == n) {
                    cout << arr[n-1];
                    break;
                }
            }
        return 0;
        }
    }
    cs

    'BOJ' 카테고리의 다른 글

    18111: 마인크래프트  (0) 2023.10.14
Designed by Tistory.