URAL2046 The First Day at School

本文详细介绍了如何帮助Vasya打印出他的大学课程周安排表,包括输入课程信息和输出表格格式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

2046. The First Day at School

Time limit: 1.0 second
Memory limit: 64 MB

Vasya is a young and very promising android. Today is his first day at University. Vasya has very carefully studied the list of all courses on the wall near the Dean’s office and has chosen the ones to attend. Now he wants to write down his own week timetable. Help him do this.

Input

The first line contains an integer n that is the number of courses Vasya is going to attend (1n12). After that the courses are listed, each is described in two lines.
The first line of a course description contains its name. The name of the course may consist of up to five words, which are divided by exactly one space (there are no spaces before the first word and after the last one). The words consist of capital and lowercase Latin letters. The length of every word is within the range from 1 to 10.
The second line of a course description contains the day of week and the number of a lesson, when it takes place. The day of week may take one of the three values: “Tuesday”, “Thursday” и “Saturday”. The number of a lesson is an integer from 1 to 4. There are no two courses, Vasya has chosen, taking place at the same time.

Output

Output the timetable as a table of the size 4×3. The columns of the table should correspond to the three academic days: the first column — to Tuesday, the second — to Thursday, the third — to Saturday. The rows should correspond to the four classes. The width of each column should be equal to 10 characters. The height of the row of the table equals to the height of the highest of its cells. If all the cells in the row are empty then the height of the row should be equal 1 character. If some word doesn’t find room in the current line, it should be placed in the next line. The text in the cell should be aligned to top and left borders. Make the table itself using characters “-” (ASCII 45), “+” (ASCII 43) and “|” (ASCII 124).

Sample

input

9
Physics
Thursday 3
Maths
Tuesday 1
Chemistry
Thursday 1
Physical education
Saturday 2
Astronomy
Saturday 4
Urban geography
Tuesday 4
History
Saturday 1
Modeling
Thursday 2
Biology
Thursday 4

output

+----------+----------+----------+
|Maths     |Chemistry |History   |
+----------+----------+----------+
|          |Modeling  |Physical  |
|          |          |education |
+----------+----------+----------+
|          |Physics   |          |
+----------+----------+----------+
|Urban     |Biology   |Astronomy |
|geography |          |          |
+----------+----------+----------+

题意

打印课表。。。

题解

注意一下换行的问题就行

AC代码

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>

using namespace std;

int n;
struct node
{
    char str[60][60];
    int num;
};
node M[3][4];
node temp;
char in[20];
char ch;
int H[5];
int x,y,len;
int d;
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    memset(M,0,sizeof M);
    for(int i=0;i<5;i++)
        H[i]=1;
    scanf("%d",&n);getchar();
    for(int i=0;i<n;i++)
    {
        gets(temp.str[0]);
        temp.num=1;
        for(int i=0;strlen(temp.str[i])>10;i++)
        {
            int j;
            if(temp.str[i][10]==' ')
                j=10;
            else
            {
                for(j=9;j>0;j--)
                    if(temp.str[i][j]==' ')
                    break;
            }
            temp.str[i][j++]=0;
            strcpy(temp.str[i+1],temp.str[i]+j);
            temp.num++;
        }
        scanf("%s",in);
        if(in[0]=='S')
            x=2;
        else if(in[0]=='T'&&in[1]=='u')
            x=0;
        else if(in[0]=='T'&&in[1]=='h')
            x=1;
        scanf("%d",&y);getchar();
        y--;
        M[x][y]=temp;
        H[y]=max(H[y],temp.num);
    }
    for(int i=0;i<4;i++)
    {
        printf("+----------+----------+----------+\n");
        for(int j=0;j<H[i];j++)
        {
            for(int k=0;k<3;k++)
            {
                putchar('|');
                if(j<M[k][i].num)
                {
                    printf("%s",M[k][i].str[j]);
                    len=strlen(M[k][i].str[j]);
                    for(int m=10-len;m;m--)
                        putchar(' ');
                }
                else
                    printf("          ");
            }
            puts("|");
        }
    }
    printf("+----------+----------+----------+");
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值