-
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:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106#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 *A = (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 'softeer 문제' 카테고리의 다른 글
Softeer [level 2] : GBC (C 언어) (0) 2023.03.30 Softeer [level 2] : 전광판 (C 언어) (0) 2023.03.30 Softeer [levle 2] 비밀 메뉴 (C 언어) (0) 2023.03.28 Softeer [level 2] : 지도 자동 구축 (C 언어) (0) 2023.03.28 Softeer [level 2] : 장애물 인식 프로그램 (C 언어) (0) 2023.03.27