개발자 톡

연습문제 톡 [21년 재직자 대회 예선] 회의실 예약

회의실 예약 반례 찾아주시면 감사드리겠습니다

등록일
2024-02-19 18:14:52
조회수
224
작성자
yimjaeyun

#include <stdio.h>

#include <string.h>

#define maxtime 100


typedef struct{

  char name[10];

}room_name;


typedef struct{

  char name[10];

  int start_time;

  int end_time;

}room_reserve;


int compare_checktime(const void* a, const void* b)

{

  int arg1 = *(const int*)a;

  int arg2 = *(const int*)b;

 

  if (arg1 < arg2) return -1;

  if (arg1 > arg2) return 1;

  return 0;

}




int main(void)

{

  int N,M;

  int temp;

  scanf("%d %d", &N,&M);

  int check_time[N][maxtime];

  int avail;

  int str_num;

  char *str_temp;

  room_name x[N];

  room_reserve y[M];

  char *str_list[N];

  int test;

  for (int i=0;i<N;i++){

    scanf("%s",x[i].name);

    str_list[i]=x[i].name;

  }


  for (int i=0;i<N-1;i++){

    for (int j=0;j<N-1;j++){

      str_num=strcmp(str_list[j],str_list[j+1]);

      if (str_num>0){

        str_temp=str_list[j];

        str_list[j]=str_list[j+1];

        str_list[j+1]=str_temp;

      }

    }

  }


  for (int i=0;i<M;i++){

    scanf("%s %d %d",y[i].name,&y[i].start_time,&y[i].end_time);

  }


  test=strcmp(str_list[0],y[0].name);

  for (int i=0;i<N;i++){

    printf("Room %s:\n",str_list[i]);

    check_time[i][0]=9;

    check_time[i][1]=18;

    temp=1;

    avail=0;


    for (int j=0;j<M;j++){

      if (strcmp(str_list[i],y[j].name)==0){

        temp+=1;

        check_time[i][temp]=y[j].start_time;

        temp+=1;

        check_time[i][temp]=y[j].end_time;

      }

     

       

      for (int i1=temp-1;i1<temp+1;i1++){

        for (int j2=0;j2<temp-1;j2++){

          if (check_time[i][i1]==check_time[i][j2]){

            check_time[i][i1]=1000;

            check_time[i][j2]=1000;

          }

        }

      }

       

      qsort(check_time[i], temp+1, sizeof(int), compare_checktime);

    }

        

    for(int j3=temp+1;j3<maxtime;j3++){

      check_time[i][j3]=1000;

    }

    

    for (int j4=0;j4<maxtime;j4++){

      if (check_time[i][j4]>100){

        avail=j4/2;

        break;

      }

    }


    if (avail==0){

      printf("Not available\n");

    }

    else{

      printf("%d available:\n",avail);

      for (int j5=0;j5<maxtime;j5++){

      if (check_time[i][j5*2]>100)

        break;

      if (check_time[i][j5*2]==9)

        printf("0%d-%d\n",check_time[i][j5*2],check_time[i][(j5)*2+1]);

      else

        printf("%d-%d\n",check_time[i][j5*2],check_time[i][(j5)*2+1]);

    }   

    }


    if (i!=N-1)

      printf("-----\n");


  }


}




Subtask 2 부분에서 계속 오류가 발생하는데 원인을 모르겠네요 ㅠㅠ

해당 예시 반례 알려주시면 감사드리겠습니다.

#[21년_재직자_대회_예선]_회의실_예약
#c언어

이 카테고리의 톡 더보기