按照格式分别输入学期,开学时间,总周数即可得到课程表,以回车结束。 eg. 学期:2021-2022_2 开学时间:2021/11/25 总周数:20
输出结果
?
#include<stdio.h>
#include<windows.h>
int Weekdayofyear(int year);
int Isprime(int year);
int Days(int year, int mouth);
int Weekday(int year, int mouth, int day);
int Max(int year,int mouth);
int main() {
char title1[] = "\t\txxxxxx大学教学日历\t\t";
char title2[] = "0000-0000学年第0学期";
char tab[60] = "周 一 二 三 四 五 六 日";
char term3;
char calender[100][8];
int tempday, tempmouth,flag = 1,b,c,d,e,f,g,h,i,j, cnt = 1, week,term1, term2,year, mouth, day;
printf("学期:");
scanf("%d-%d_%c", &term1, &term2, &term3);
printf("开学时间:");
scanf("%d/%d/%d", &year, &mouth, &day);;
printf("总周数:");
scanf("%d", &week);
tempday = day;
tempmouth = mouth;
for (b = 3; b >= 0; b--)
{
title2[b] = term1 % 10 + 48;
term1 /= 10;
}
for (c = 8; c >= 5; c--)
{
title2[c] = term2 % 10 + 48;
term2 /= 10;
}
title2[15] = term3;
for (d = 0; d < week; d++) {
calender[d][0] = d + 1;
}
for (e = 0; e < week; e++) {
for (f = 1; f < 8; f++) {
if (e == 0) {
for (g = 1; g < Weekday(year, mouth, day); g++) {
calender[e][g] = 0;
}
for (h = Weekday(year, mouth, day);h < 8; h++) {
calender[e][h] = day++;
}
break;
}
if (day > Max(year, mouth)) {
mouth += 1;
if (mouth > 12) {
mouth = 1;
}
calender[e][f] = -mouth;
day = 2;
}
else {
calender[e][f] = day++;
}
}
}
puts(title1);
printf("\t\t ");
puts(title2);
puts(tab);
for (i = 0; i < week; i++) {
for (j = 0; j < 8; j++) {
if (calender[i][j] == 0) {
printf(" \t");
continue;
}
if (calender[i][j] < 0) {
// SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15 | 0 | 128 | 0);
printf("%d月\t", -calender[i][j]);
// SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7 | 0 | 0 | 0);
}
else {
printf("%2d\t", calender[i][j]);
}
}
printf("\n");
}
}
int Weekdayofyear(int year) {
int days = 0, week;
int a;
for (a = 0; a < year - 1900; a++) {
if (a % 4 == 0) days += 366;
else days += 365;
}
week = days % 7;
if (week == 0) week = 7;
return week;
}
int Isprime(int year) {
char flag;
if (year % 4 == 0) {
flag = 1;
}
else {
flag = 0;
}
return flag;
}
int Days(int year, int mouth) {
int days = 0;
int isprime;
isprime = Isprime(year);
switch (mouth) {
case 12:days += 31;
case 11:days += 30;
case 10:days += 31;
case 9:days += 30;
case 8:days += 31;
case 7:days += 31;
case 6:days += 30;
case 5:days += 31;
case 4:days += 30;
case 3:days += 31;
case 2:if (isprime == 1) days += 29;
else days += 28;
case 1:days += 31;
}
return days;
}
int Weekday(int year, int mouth, int day) {
int days;
int weekday;
days = Days(year, mouth - 1);
days += day;
weekday = days % 7;
weekday = weekday + Weekdayofyear(year) - 1;
if (weekday > 7) weekday -= 7;
return weekday;
}
int Max(int year,int mouth) {
int days;
int isprime;
isprime = Isprime(year);
switch (mouth) {
case 12:days = 31; break;
case 11:days = 30; break;
case 10:days = 31; break;
case 9:days = 30; break;
case 8:days = 31; break;
case 7:days = 31; break;
case 6:days = 30; break;
case 5:days = 31; break;
case 4:days = 30; break;
case 3:days = 31; break;
case 2:if (isprime == 1) days = 29;
else days = 28; break;
case 1:days = 31; break;
}
return days;
}
|