Submission
Status:
PPPPT
Subtask/Task Score:
80/100
Score: 80
User: wasupum
Problemset: ชั้นหนังสือ
Language: c
Time: 2.093 second
Submitted On: 2025-10-18 23:12:22
#include <stdio.h>
#include <string.h>
void bubblesort(char book[][35],int n){
char temp[35];
for(int i = 0 ; i < n-1 ; i++){
for(int j = 0 ; j < n-i-1 ; j++){
if(strcmp(book[j],book[j+1])>0){
strcpy(temp, book[j]);
strcpy(book[j], book[j+1]);
strcpy(book[j+1], temp);
}
}
}
}
int main(void){
int L, N;
scanf("%d %d",&L,&N);
char book[N*10][35];
int allk = 0;
int index = 0 ;
for(int i = 0 ; i < N ; i++){
int k ;
char temp[35];
scanf("%d %s",&k,temp);
for(int j = 0 ; j < k ;j++){
strcpy(book[index],temp);
index++;
}
allk += k;
}
bubblesort(book,allk);
char shelf[35][allk*2+2];
for(int i = 0 ; i <= L+1; i++){
for(int j = 0 ; j <= allk*2; j++){
if(j%2 == 0) shelf[i][j]='|';
else shelf[i][j]='.';
if(i == 0 || i == L+1){
if(j%2==0) shelf[i][j]='+';
else shelf[i][j]='-';
}
}
shelf[i][allk*2+1]='\0';
}
for(int i = 0 ; i < L ; i++){
for(int j = 0 ; j < allk ; j++){
if(j%2==1){
size_t len = strlen(book[j]);
if(i >= L-len)shelf[i+1][(j*2)+1] = book[j][L-i-1];
}else{
if(i < strlen(book[j]))shelf[i+1][(j*2)+1] = book[j][i];
}
}
}
for(int i = 0 ; i <= L+1 ; i++){
printf("%s\n",shelf[i]);
}
return 0;
}