您的位置:首页 > 其它

USACO 1.1 Friday the Thirteenth

2015-09-09 09:12 507 查看
#include <stdio.h>
#define DEBUG 0
#define TESTCASES 8

#define MONTHS 12
#define DAYS 7

int daysOfMonth[MONTHS + 1] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int daysOfDay[DAYS + 1];

int main(){
#if DEBUG
int testCase;
for (testCase = 1; testCase <= TESTCASES; testCase++){
char inputFileName[11]= "inputx.txt";
inputFileName[5] = '0' + (testCase - 0);
freopen(inputFileName, "r", stdin);
printf("#%d\n", testCase);
#endif

int numOfYears;
scanf("%d", &numOfYears);

int day;
for (day = 1; day <= DAYS; day++)
daysOfDay[day] = 0;

int days = 0;
int years;
for (years = 1; years <= numOfYears; years++){
int year = 1900 + years - 1;

if ( year % 400 == 0 || (year % 100 != 0 && year % 4 == 0) )
daysOfMonth[2] = 29;
else
daysOfMonth[2] = 28;

int month;
for (month = 1; month <= MONTHS; month++){
int day = (days + 13) % DAYS;
if (day == 0)
day = 7;
daysOfDay[day]++;
days += daysOfMonth[month];
}
}

printf("%d %d ", daysOfDay[6], daysOfDay[7]);
for (day = 1; day <= 5; day++)
printf("%d%c", daysOfDay[day], day == 5 ? '\n' : ' ');

#if DEBUG
}
#endif
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息