1 条题解

  • 0
    @ 2023-3-30 22:27:22

    C :

    #include<stdio.h>
    
    int leap(int y)
    {
    	return (y%4==0&&y%100!=0)||(y%400==0);
    }
    
    int main()
    {
    	int M[][2]={0,0,
    				31,31,
    				28,29,
    				31,31,
    				30,30,
    				31,31,
    				30,30,
    				31,31,
    				31,31,
    				30,30,
    				31,31,
    				30,30,
    				31,31};
    	int y,m,d,i,j,s;
    	while(scanf("%d-%d-%d",&y,&m,&d)!=EOF)
    	{
    		for(s=i=0;i<y;i++)
    			if(leap(i))
    				s+=366;
    			else
    				s+=365;
    		for(i=1;i<m;i++)
    			if(leap(y))
    				s+=M[i][1];
    			else
    				s+=M[i][0];
    		s+=d;
    		printf("%d\n",735302-s);
    	}
    	return 0;
    }
    

    C++ :

    #include<iostream>
    #include<cstdio>
    #include<cmath>
    using namespace std;
    
    struct dat
    {
        int year;
        int month;
        int day;
    }n,b;
    
    int run(dat a)
    {
        if((a.year%4==0&&a.year%100!=0)||a.year%400==0)
            return 1;
        else
            return 0;
    }
    long long  days(dat a)
    {
        long long ans = 0;
        ans = (a.year*365+a.year/4-a.year/100+a.year/400);
        switch (a.month)
        {
            case 12:ans+=30;
            case 11:ans+=31;
            case 10:ans+=30;
            case 9:ans+=31;
            case 8:ans+=31;
            case 7:ans+=30;
            case 6:ans+=31;
            case 5:ans+=30;
            case 4:ans+=31;
            case 3:ans+=28;
            case 2:ans+=31;
            case 1:ans+=a.day;if(run(a)&&(a.month<2||(a.month==2&&a.day==29)))ans--;
        }
        return ans;
    }
    int main()
    {
      //  freopen("in.txt","r",stdin);
        n.year = 2013;
        n.month = 3;
        n.day = 9;
        long long nn,bb;
        nn = days(n);
        while(scanf("%d-%d-%d",&b.year,&b.month,&b.day)!=EOF)
        {
            bb = days(b);
          //  cout<<nn<<" "<<bb<<endl;
            cout<<fabs(nn-bb)<<endl;
        }
    }
    
    
    • 1

    信息

    ID
    1746
    时间
    1000ms
    内存
    128MiB
    难度
    10
    标签
    (无)
    递交数
    6
    已通过
    1
    上传者