WOJ1019-Curriculum Schedule

New semester has begun, a lot of students are going to print out their curriculum schedules. They are using the same template, as the
following table shows:

Each student has a list of courses, and the items in the list are of this format:

COURSE_NAME: DAY TIME_SECTION CLASS_NUMBER

COURSE_NAME is the name of the course, which contains no more than 9 characters. Note, the COURSE_NAME may contains white spaces, but NO
trailing or leading white spaces.
DAY is one of the strings of ?MON?, ?TUE?, ?WED?, ?THU?, ?FRI?, respectively representing one of the workday of a week.
TIME_SECTION would be either ?Morning? or ?Afternoon?.
CLASS_NUMBER tells the course will be given in the CLASS_NUMBERth class in the morning or afternoon. If the TIME_SECTION is Morning, the
CLASS_NUMBER is less than 4, and If the TIME_SECTION is Afternoon, the CLASS_NUMBER is less than 3.
Given a list of the courses, just fill every course name to a specific blank in the schedule table.

输入格式

There are several test cases. Each test case has an integer n, representing the number of courses that listing in the list. Then n lines follow,
each of which are of the form:

COURSE_NAME: DAY TIME_SECTION CLASS_NUMBER

No two different courses are arranged to the same time of the same day.

输出格式

Output the schedule table. Note, since every blank in the schedule table has 11 spaces, while the length of the course name is no more than 9. So,
you can easily put the name to the blank without any effort. Make sure the course name is written in the middle of the blank. This also can be
easily done if the length of the course name is odd. Otherwise, you can add a white space to the end of the course name, then the length of the
course name becomes an odd number.
See the sample output for more details. Print a blank line after each test case.

样例输入

4
Algorithm: WED Morning 2
Algorithm: MON Afternoon 1
Data Base: TUE Afternoon 2
Wavelet: FRI Morning 4

2
Math: MON Morning 1
Computer: FRI Afternoon 3

按照题目做就可以了,水题

#include<stdio.h>
#include<string.h>
void input(char* s){
	int i=0;
	char c;
	getchar();
	while(scanf("%c",&c)&&c!=':'){
		s[i]=c;
		i++;
	}
	s[i]='\0';
}
int main(){
	char cou[15],coutab[7][5][15],day[5],mon[10];
	int yntab[7][5];
	int i,j,k,l,len,dayi,n,cnum;
	while(scanf("%d",&n)==1){
		memset(yntab,0,35*sizeof(int));
		while(n-->0){
			input(cou);
			scanf("%s %s %d",&day,&mon,&cnum);
			if(!strcmp(day,"MON"))
			dayi=0;
			else if(!strcmp(day,"TUE"))
			dayi=1;
			else if(!strcmp(day,"WED"))
			dayi=2;
			else if(!strcmp(day,"THU"))
			dayi=3;
			else if(!strcmp(day,"FRI"))
			dayi=4;
			if(!strcmp(mon,"Morning"))
			cnum-=1;
			else
			cnum+=3;
			yntab[cnum][dayi]=1;
			strcpy(coutab[cnum][dayi],cou);
		}
		printf("+-----+-----------+-----------+-----------+-----------+-----------+\n"
			   "|     |    MON    |    TUE    |    WED    |    THU    |    FRI    |\n"
			   "+-----+-----------+-----------+-----------+-----------+-----------+\n"
			   "|                          Morning                                |\n"
			   "+-----+-----------+-----------+-----------+-----------+-----------+\n"
			   );
		for(i=0;i<4;i++){
			printf("|  %d  |",i+1);
			for(j=0;j<5;j++){
				if(yntab[i][j]){
					len=strlen(coutab[i][j]);
					if(!(len&1)){
						coutab[i][j][len]=' ';
						len++;
						coutab[i][j][len]='\0';
					}
					k=(11-len)/2;
					for(l=0;l<k;l++)
					printf(" ");
					printf("%s",coutab[i][j]);
					for(l=0;l<k;l++)
					printf(" ");
					printf("|");
				} 
				else
				printf("           |"); 
			}
			printf("\n");
			printf("+-----+-----------+-----------+-----------+-----------+-----------+\n");
		} 
		printf("|                         Afternoon                               |\n"
			   "+-----+-----------+-----------+-----------+-----------+-----------+\n");
		for(i=4;i<7;i++){
			printf("|  %d  |",i-3);
			for(j=0;j<5;j++){
				if(yntab[i][j]){
					len=strlen(coutab[i][j]);
					if(!(len&1)){
						coutab[i][j][len]=' ';
						len++;
						coutab[i][j][len]='\0';
					}
					k=(11-len)/2;
					for(l=0;l<k;l++)
					printf(" ");
					printf("%s",coutab[i][j]);
					for(l=0;l<k;l++)
					printf(" ");
					printf("|");
				} 
				else
				printf("           |"); 
			}
			printf("\n");
			printf("+-----+-----------+-----------+-----------+-----------+-----------+\n");
		}
		printf("\n");
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值