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

static	char    dai[N+1][M+1],kyokan[N+1][M+1],heya[N+1][M+1],you[N+1][M+1];
static	int     gen[N+1],gakki[N+1],kaisi[N+1];
static	char    s[N+1];

main(int argc,char *argv[]) {
	int  i,j,h,count;
	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",dai[j],&kaisi[j],&gakki[j],you[j],&gen[j],kyokan[j],heya[j]);
                ++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);

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

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

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

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

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

                }
        printf("</table>\n");
        }

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

}
