개발자 톡
c언어 반례 부탁드립니다...!
- 등록일
- 2024-04-14 15:28:50
- 조회수
- 289
- 작성자
- hdy3233
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(void)
{
char room[50][2][11] = {0,};
char room_name[11] = {0,};
char output[50][11] = {0,};
char temp[11];
char temp_cnt;
char room_name_output[50][11] = {0,};
int count[50] = {0,};
int n; //회의실 개수
int m; //예약된 회의의 개수
int start_time;
int end_time;
int same;
int current;
int cnt;
int zero_cnt[50];
scanf("%d %d", &n, &m);
for(int i = 0 ; i < n ; i++)
{
scanf("%s", room[i][0]);
}
for(int i = 0 ; i < m ; i++)
{
scanf("%s %d %d", room_name, &start_time, &end_time);
for(int j = 0 ; j < n ; j++)
{
same = strcmp(room_name, room[j][0]);
if(same == 0)
{
for(int k = 0 ; k < end_time - (start_time - 1) ; k++)
{
room[j][1][start_time - 9 + k] += 1;
}
}
}
}
for(int i = 0 ; i < n ; i++)
{
zero_cnt[i] = 0;
cnt = 0;
current = 1;
for(int j = 0 ; j < 10 ; j++)
{
if(current == 1 && room[i][1][j] == 0 && j == 0)
{
current = 0;
output[i][cnt++] = j + 9;
}
else if(current == 0 && room[i][1][j] == 0 && j == 9)
{
current = 0;
output[i][cnt++] = j + 9;
}
else if(current == 1 && room[i][1][j] == 0 && j == 9)
{
current = 0;
output[i][cnt++] = j + 8;
output[i][cnt++] = j + 9;
}
else if(current == 1 && room[i][1][j] == 0)
{
current = 0;
output[i][cnt++] = j + 8;
}
else if(current == 0 && room[i][1][j] == 1)
{
current = 1;
output[i][cnt++] = j + 9;
}
}
count[i] = cnt / 2;
}
for(int i = 0 ; i < n ; i++)
{
strcpy(room_name_output[i], room[i][0]);
}
for (int i = 0; i < n - 1; i++)
{
for (int j = i + 1; j < n; j++)
{
if (strcmp(room_name_output[i], room_name_output[j]) > 0)
{
strcpy(temp, room_name_output[i]);
strcpy(room_name_output[i], room_name_output[j]);
strcpy(room_name_output[j], temp);
strcpy(temp, output[i]);
strcpy(output[i], output[j]);
strcpy(output[j], temp);
temp_cnt = count[i];
count[i] = count[j];
count[j] = temp_cnt;
}
}
}
for(int i = 0 ; i < n ; i++)
{
printf("Room %s:\n", room_name_output[i]);
if(count[i] == 0)
{
printf("Not available");
if( i < n - 1)
{
printf("\n");
}
if(i < n - 1)
{
printf("-----\n");
}
continue;
}
printf("%d available:\n", count[i]);
for(int j = 0 ; j < count[i] ; j ++)
{
printf("%02d-%02d", output[i][j * 2], output[i][(j * 2) + 1]);
if( i < n - 1 || j < count[i] - 1)
{
printf("\n");
}
}
if(i != n -1)
{
printf("-----\n");
}
}
system("pause");
return 0;
}