Submission
Status:
x---T
Score: 0
User: akuyga1
Problemset: ชั้นหนังสือ
Language: c
Time: 2.021 second
Submitted On: 2024-10-02 13:58:04
#include<stdio.h>
#include<string.h>
int main(){
int N,L;
scanf("%d",&L);
scanf(" %d\n",&N);
char index[N*10][L+1];
int x;
char y[L+1];
int count=0;
for(int i=0;i<N;i++){
scanf("%d",&x);
scanf(" %s",y);
for(int j=0;j<x;j++)
{strcpy(index[count],y);
count++;
}
}
//now all the book is cover up
//we now have count book and last index is count-1
//selection sort
for(int i=0;i<count;i++)//i is the base
for(int j=1;j<count-i;j++)//i+j is a array to compare
for(int k=0;k<L;k++)
{
if((int)index[i][k]>(int)index[i+j][k]){
char temp[L+1];
strcpy(index[i],temp);
strcpy(index[i+j],index[i]);
strcpy(temp,index[i+j]);
break;
}}
//top shelf
for(int i=0;i<count;i++)
printf("+-");
printf("+\n");
//each ladder
for(int i=0;i<L;i++){ //i is line
printf("|");
for(int j=0;j<count;j++){
if(j%2==0)printf("%c",index[j][i]);
if(j%2==1)printf("%c",index[j][L-i-1]);
printf("|");}
printf("\n");
}
for(int i=0;i<count;i++)
printf("+-");
printf("+\n");
}