Friday the Thirteenth

/*
ID: mrster.1
LANG: C
TASK: friday
*/

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n = 0;
    int countDays = 0;
    int week[7];
    int i = 0,j;
    FILE *fin = fopen("friday.in","r");
    FILE *fout = fopen("friday.out","w");
    for(i = 0;i<7;i++)
    {
        week[i] = 0;
    }
    fscanf(fin,"%d",&n);
    countDays = countDay(1899+n,12,31);
    for(i = 1;i<=n;i++)
    {
        for(j = 1;j<=12;j++)
        {
            countDays = countDay(1899+i,j,13);
            week[(countDays-1)%7]++;
        }
    }
    fprintf(fout,"%d %d ",week[5],week[6]);
    for(i = 0;i<5;i++)
    {
        if(i!=4)fprintf(fout,"%d ",week[i]);
        else fprintf(fout,"%d",week[i]);
    }
    fprintf(fout,"\n");
}

int countDay(int year,int month,int day)
{
    int countDay = 0;
    int i = 0;
    for(i = 1900;i<year;i++)
    {
        if(isLeapYear(i)==1)countDay += 366;
        else countDay +=365;
    }
    countDay +=countCurrentDay(year,month,day);
    return countDay;
}

int countCurrentDay(int year,int month,int day)
{
    int countDay = 0;
    int flag = 0;
    flag = isLeapYear(year);
    switch(month-1)
    {
        case 11 :countDay+=30;
        case 10 :countDay+=31;
        case 9 :countDay+=30;
        case 8 :countDay+=31;
        case 7 :countDay+=31;
        case 6 :countDay+=30;
        case 5 :countDay+=31;
        case 4 :countDay+=30;
        case 3 :countDay+=31;
        case 2 :countDay+=28+flag;
        case 1 :countDay+=31;
        break;
    }
    countDay +=day;
    return countDay;
}

int isLeapYear(int year)
{
    int flag = 0;
    if(year%100!=0)
    {
        if(year%4==0)flag = 1;
    }
    else if(year%100==0)
    {
        if(year%400==0)flag = 1;
    }
    return flag;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值