아직 계정이 없으신가요? 회원가입

Dev. Talk

반례 부탁드립니다! [21년 재직자 대회 예선] 회의실예약

회원사진ryucha
186 views2021-12-20 14:29


#include <iostream>
#include <string>
#include <sstream>
#include <cstring>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int cpr(char* A, char* B)
{
	/*값이 크면 순서가 아래임 return 1*/ 
	if(A[0] > B[0])
	{
		return 1;
	}
	
	else if(A[0] < B[0])
	{
		return 0;
	}
	
	else
	{
		if(A[0] == '')
		{
			return 1;	
		}
		
		else
		{
			if(A[1] > B[1])
			{
				return 1;
			}
			
			else if(A[1] < B[1])
			{
				return 0;
			}
			
			else
			{
				if(A[1] == '')
				{
					return 1;	
				}
				
				else
				{
					if(A[2] > B[2])
					{
						return 1;
					}
					
					else if(A[2] < B[2])
					{
						return 0;
					}
					
					else
					{
						if(A[2] == '')
						{
							return 1;	
						}
						
						else
						{
							if(A[3] > B[3])
							{
								return 1;
							}
							
							else if(A[3] < B[3])
							{
								return 0;
							}
							
							else
							{
								if(A[3] == '')
								{
									return 1;	
								}
								
								else
								{
									if(A[4] > B[4])
									{
										return 1;
									}
									
									else if(A[4] < B[4])
									{
										return 0;
									}
									
									else
									{
										if(A[4] == '')
										{
											return 1;	
										}
										
										else
										{
											if(A[5] > B[5])
											{
												return 1;
											}
											
											else if(A[5] < B[5])
											{
												return 0;
											}
											
											else
											{
												if(A[5] == '')
												{
													return 1;	
												}
												
												else
												{
													if(A[6] > B[6])
													{
														return 1;
													}
													
													else if(A[6] < B[6])
													{
														return 0;
													}
													
													else
													{
														if(A[6] == '')
														{
															return 1;	
														}
														
														else
														{
															if(A[7] > B[7])
															{
																return 1;
															}
															
															else if(A[7] < B[7])
															{
																return 0;
															}
															
															else
															{
																if(A[7] == '')
																{
																	return 1;	
																}
																
																else
																{
																	if(A[8] > B[8])
																	{
																		return 1;
																	}
																	
																	else if(A[8] < B[8])
																	{
																		return 0;
																	}
																	
																	else
																	{
																		if(A[8] == '')
																		{
																			return 1;	
																		}
																		
																		else
																		{
																			if(A[9] >= B[9])
																			{
																				return 1;
																			}
																			
																			else if(A[9] < B[9])
																			{
																				return 0;
																			}
																		}
																	}
																}
															}
														}
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
}

void swap_char(char* A, char* B)
{
	char C[10];
	memcpy(C, A, 10);
	memcpy(A, B, 10);
	memcpy(B, C, 10);	
}

int main(int argc, char** argv) {

    int N;
    int M;
    char** RoomName;
    char** RoomNameA;
    int** M_A;
    int* RANum;
    
    std::cin>>N;
    std::cin>>M;
 
    RoomName = new char* [N];   
    RoomNameA = new char* [N];     
    M_A = new int* [N];
    RANum = new int[N];
    
    for (int i = 0; i < N; i++)
    {
     	RoomName[i] = new char[10];   
     	RoomNameA[i] = new char[10];   
     	M_A[i] = new int[10];
    }
    
     for (int i = 0; i < N; i++)
    {
    	RANum[i] = 0;
    	for(int j=0;j<10;j++)
    	{
			RoomName[i][j] = 0;
			M_A[i][j] = 0;
		}
			M_A[i][9] = 1;
	}
	
 	for(int i=0;i<N;i++)
	{
		std:: cin >> RoomName[i];
	}   
	
	for(int j=0;j<N;j++)
	{
		for(int i=0;i<N-1;i++)
		{	    
			if(cpr(RoomName[i], RoomName[i+1]))
			{
				swap_char(RoomName[i], RoomName[i+1]);
			}
		}	
	}
		
		
		int M_AL[10] = {0,};
		

		
	for(int i=0;i<M;i++)
	{
    	char RoomNameL[10] = {0,};
		int s_t, f_t;
		int f = 0;
		
		std::cin >> RoomNameL >> s_t>>f_t;
		
		for(int j=0;j<N;j++)
		{
			if((RoomName[j][0] == RoomNameL[0])&&(RoomName[j][1] == RoomNameL[1])&&(RoomName[j][2] == RoomNameL[2])&&(RoomName[j][3] == RoomNameL[3])&&(RoomName[j][4] == RoomNameL[4])
			&&(RoomName[j][5] == RoomNameL[5])&&(RoomName[j][6] == RoomNameL[6])&&(RoomName[j][7] == RoomNameL[7])&&(RoomName[j][8] == RoomNameL[8])&&(RoomName[j][9] == RoomNameL[9]))
			{				
				if((s_t < f_t) && (s_t >8) && (s_t<19)&& (f_t >8) && (f_t<19))
				{	
					s_t = s_t -9;
					f_t = f_t -10;		
					for(int k=s_t;k<=f_t; k++)
					{
						M_AL[k] = 1;
					}
					
					for(int x=0;x<9;x++)
					{
						if((M_AL[x] == 1) &&(M_A[j][x]==1))
						{
							f = 1;
						}
					}
						
					if(f!=1)
					{
							
						for(int k=s_t;k<=f_t; k++)
						{
							M_A[j][k] = 1;
						}
					}
					
					f=0;
					
					for(int x=0;x<10;x++)
					{
						M_AL[x] = 0;
					}
				}
			}
		}		
	}
	
	std::cout<<"
";	
		
	for(int i=0;i<N;i++)
	{
		for(int j=0;j<9;j++)
		{
			if((M_A[i][j] == 0) && (M_A[i][j+1] == 1))
			{
				RANum[i]++;
			}
		}
		
		if((M_A[i][0] == 0) && (M_A[i][1] == 0) && (M_A[i][2] == 0) && (M_A[i][3] == 0) && (M_A[i][4] == 0) && (M_A[i][5] == 0) && (M_A[i][6] == 0) && (M_A[i][7] == 0) && (M_A[i][8] == 0))
		{
			std::cout<<"Room"<<" "<<RoomName[i]<<":
"<<"1 available:
"<<"09-18
"<<"-----
";
		}
		
		else if((M_A[i][0] == 1) && (M_A[i][1] == 1) && (M_A[i][2] == 1) && (M_A[i][3] == 1) && (M_A[i][4] == 1) && (M_A[i][5] == 1) && (M_A[i][6] == 1) && (M_A[i][7] == 1) && (M_A[i][8] == 1))
		{
			std::cout<<"Room"<<" "<<RoomName[i]<<":
"<<"Not available
"<<"-----
";
		}
		else
		{
			std::cout<<"Room"<<" "<<RoomName[i]<<":
"<<RANum[i]<<" available:
";
		
				for(int k=0;k<9;k++)
				{
					if(k==0)
					{
						if(M_A[i][k]==0)
						{
							std::cout<<"0"<<k+9<<"-";
						}
						
						if((M_A[i][k]==0)&&(M_A[i][k+1]==1))
						{
							std::cout<<k+10<<"
";
						}
					}
					
					else
					{
						if((M_A[i][k-1]==1)&&(M_A[i][k]==0))
						{
							std::cout<<k+9<<"-";	
						}
						
						if((M_A[i][k]==0)&&(M_A[i][k+1]==1))
						{
							std::cout<<k+10<<"
";
						}
					}
				}
		
			if(i!=N-1)
			{
				std::cout<<"-----
";		
			}
		}
	}
	
	for(int i=0;i<N;i++)
	{
		delete[] RoomName[i];
		delete[] M_A[i];
	}
	
	delete[] RoomName;
	delete[] M_A;
	
	return 0;
}<br>

ㄱrkatkgkqslek.

감사합니다.^^