Submission
Status:
P--xx
Subtask/Task Score:
20/100
Score: 20
User: Whatthepoop
Problemset: ชั้นหนังสือ
Language: c
Time: 0.002 second
Submitted On: 2025-10-10 23:15:24
#include <stdio.h>
#include <string.h>
typedef struct {
int amount;
char name[31];
} Bookshelf;
void reverse(char str[]) {
int len = strlen(str);
int i = 0, j = len - 1;
while(i < j) {
char temp = str[i];
str[i] = str[j];
str[j] = temp;
i++;
j--;
}
}
int main(){
int L, N;
scanf("%d %d", &L, &N);
Bookshelf s[N];
int max = -1e9;
for(int i = 0; i < N; i++){
scanf("%d %s", &s[i].amount, &s[i].name);
}
char book[31][2500];
int size = 0;
for(int i = 0; i < N; i++){
while(s[i].amount > 0){
strcpy(book[size], s[i].name);
size++;
s[i].amount--;
}
}
for(int i = 0; i < size-1; i++){
for(int j = 0; j < size-i-1; j++){
if(book[j][0] > book[j+1][0]){
char temp[2500];
strcpy(temp, book[j]);
strcpy(book[j], book[j+1]);
strcpy(book[j+1], temp);
}
}
}
for(int i = 0; i < size; i++){
if(i%2 == 1){
reverse(book[i]);
}
}
for(int i = 0; i < size; i++){
int len = strlen(book[i]);
if(len < L){
char space[L+1];
space[0] = '\0';
while(len < L){
strcat(space, " ");
len++;
}
strcat(space, book[i]);
strcpy(book[i], space);
}
}
for(int i = 0; i < size; i++){
printf("+-");
}
printf("+\n");
for(int j = 0; j < L; j++){
for(int i = 0; i < size; i++){
printf("|%c", book[i][j]);
}
printf("|\n");
}
for(int i = 0; i < size; i++){
printf("+-");
}
printf("+\n");
return 0;
}