ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Softeer [level 2] : 회의실 예약 (C 언어)
    softeer 문제 2023. 3. 29. 23:08

    https://softeer.ai/practice/info.do?idx=1&eid=626&sw_prbl_sbms_sn=171259 

     

    Softeer

    연습문제를 담을 Set을 선택해주세요. 취소 확인

    softeer.ai

    Code:

    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
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
     
    typedef struct {
        char name[11];
        int time[20][20];
    }abc;
     
    int compare(const void* a, const void* b)
    {
        abc *= (abc*)a;
        abc* B = (abc*)b;
        return strcmp(A->name, B->name);
    }
     
    int main()
    {
        int n, m;
        scanf("%d %d"&n, &m);
        abc arr[51= { 0, };
        char chname[11= { 0, };
        int start=0,end=0;
        int count = 0;
        int nums[51][20= { 0, };
        int nume[51][20= { 0, };
        int cnt = 0;
        int a = 0;
        int b = 0;
        for (int i = 0; i < n; i++)
        {
            scanf("%s", arr[i].name);
        }
        while (m--)
        {
            scanf("%s %d %d"&chname, &start, &end);
            for (int i = 0; i < n; i++)
            {
                if (!(strcmp(chname, arr[i].name)))
                {
                    for (int j = start; j < end; j++)
                    {
                        arr[i].time[j][j+1= 1;
                    }
                    break;
                }
            }
        }
        for (int i = 0; i < n; i++)
        {
            arr[i].time[8][9= 1;
            arr[i].time[18][19= 1;
        }
        qsort(arr, n, sizeof(abc), compare);
        for (int i = 0; i < n; i++)
        {
            a = 0;
            b = 0;
            cnt = 0;
                printf("Room %s:\n", arr[i].name);
                for (int j = 8; j <= 17; j++)
                {
                    if (arr[i].time[j][j+1== 1&&arr[i].time[j+1][j+2]==0)
                    {
                        nums[i][a++= j+1;
                    }
                    if (arr[i].time[j][j+1== 0 && arr[i].time[j + 1][j+2== 1)
                    {
                        if (j != 18)
                        {
                            nume[i][b++= j + 1;
                        }
                        else
                        {
                            nume[i][b++= j;
                        }
                        cnt++;
                    }
                }
                if (cnt > 0)
                {
                    printf("%d available:\n", cnt);
                }
                else
                {
                    printf("Not available\n");
                }
                for (int j = 0; j < a; j++)
                {
                    if ((nums[i][j]) / 10 == 0)
                    {
                        printf("0%d", nums[i][j]);
                    }
                    else
                    {
                        printf("%d", nums[i][j]);
                    }
                    printf("-");
                    printf("%d\n", nume[i][j]);
                }
                if (i != n - 1)
                {
                    printf("-----\n");
                }
        }    
    }
    cs

Designed by Tistory.