#include<stdio.h>
#define M 80
#define N 100

static	char    s[N+1];

struct kougi_t {
	char dai[M];
	char kyokan[M];
	char heya[M];
	char you[M];
	int  gen;
	int  gakki;
	int  kaisi;
};
static struct kougi_t kougi[N];  

static char *dayname[]={"月","火","水","木","金"};

main(int argc,char *argv[]) {
	int  i,j,h,count,dow;
	FILE *fin;

        if(argc!=2) {
                fprintf(stderr,"プログラム名　対象データファイル\nと書いてください\n例 a.out jugyo.dat\n");
                exit(1);
        }
        if ((fin=fopen(argv[1],"r"))==NULL) {
		fprintf(stderr,"File not found\n");
		exit(1);
	}

	j = 0;
	while(fgets(s,500,fin) != NULL){
                sscanf(s,"%s %d %d %s %d %s %s",kougi[j].dai,&kougi[j].kaisi,&kougi[j].gakki,kougi[j].you,&kougi[j].gen,kougi[j].kyokan,kougi[j].heya);
                ++j;
        }

        count=j;

        printf("<html><head><title>９９年度時間割り</title></head>\n");
        for(h=1;h<=2;++h){
                printf("<h2>%d 学期</h2> <table border>\n",h);
                printf("<tr><td><th>月 <th>火 <th>水 <th>木 <th>金\n");

                for(i=1;i<=5;++i){
                        printf("<tr><th>%d\n",i);

			for(dow=0;dow<5;dow++) {
				printf("<td><!--%s-->\n",dayname[dow]);
                        	for(j=0;j<count;++j){
                                	if(strcmp(dayname[dow],kougi[j].you)==0 && kougi[j].gakki==h && kougi[j].gen==i)
                                	printf("%s (%d)<br> %s %s<hr>\n",kougi[j].dai,kougi[j].kaisi,kougi[j].kyokan,kougi[j].heya);
                        	}
			}
                }
        printf("</table>\n");
        }

        printf("</body></html>\n");

}
