mirror of
https://gitlab.gwdg.de/j.hahn02/university.git
synced 2026-01-01 14:54:25 -05:00
39 lines
920 B
C
39 lines
920 B
C
#include<stdio.h>
|
|
|
|
// Lists to define the calendar
|
|
char *day[7] = {"Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag"};
|
|
int months[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
|
int leap = 29;
|
|
|
|
// Check for leap year
|
|
int isleap(int y) {
|
|
return ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0);
|
|
}
|
|
|
|
int main() {
|
|
// Stating date for the 1.1.1600 is a Saturday
|
|
int n = 5;
|
|
|
|
// Read in the date
|
|
int d, m, y;
|
|
scanf("%d.%d.%d", &d, &m, &y);
|
|
// Check for errors
|
|
if (d < 1 || m < 1 || m > 12 || d > months[m-1] || y < 1600 || y > 4000) return 1;
|
|
|
|
// Get the number of days passed
|
|
for (int i = 1600; i < y; i++) {
|
|
if (isleap(i)) n+= 366;
|
|
else n += 365;
|
|
}
|
|
for (int i = 0; i < m - 1; i++) {
|
|
if (isleap(y)) {
|
|
if (i == 1) n += leap;
|
|
else n += months[i];
|
|
} else n += months[i];
|
|
}
|
|
n += d - 1;
|
|
|
|
// Print the day
|
|
printf("%s\n", day[n % 7]);
|
|
}
|