1 条题解

  • 0
    @ 2025-11-30 16:26:39

    C :

    #include<stdio.h>
    int main()
    {
    	int n,m;
    	while(scanf("%d %d",&n,&m)!=EOF)
    	{
    		int i,j,k=1,s=1,a[6][7];
    		for(i=0;i<6;i++)
    			for(j=0;j<7;j++)
    				a[i][j]=0;
    		int tab[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    		int t=tab[m];
    		if((n%4==0&&n%100!=0||n%400==0)&&m==2)
    			t=t+1;
    		if(m==1||m==2)
    		{
    			m=m+12;
    			n=n-1;
    		}
    		int w;
    		w=(1+2*m+3*(m+1)/5+n+n/4-n/100+n/400+1)%7;	
    		printf("Su Mo Tu We Th Fr Sa\n");
    		for(i=w;i<7;i++)
    			a[0][i]=k++;
    		if(a[0][0]==1)
    		{
    			printf(" 1");
    			s++;
    		}
    		else
    			printf("  ");
    		for(i=1;i<7;i++)
    		{
    			if(a[0][i]!=0)
    			{
    				s++;
    				printf(" %2d",a[0][i]);
    			}
    			else
    				printf("   ");
    		}
    		printf("\n");
    		int ok=0;
    		for(i=1;i<6;i++)
    		{
    			for(j=0;j<7;j++)
    			{
    				a[i][j]=k++;
    				if(k>t)
    				{
    					ok=1;
    					break;
    				}
    			}
    			if(ok)
    				break;
    		}
    		ok=0;
    		for(i=1;i<6;i++)
    		{
    			printf("%2d",a[i][0]);
    			s++;
    			if(k==s)
    			{
    				printf("\n");
    				break;
    			}
    			for(j=1;j<7;j++)
    			{
    				printf(" %2d",a[i][j]);
    				s++;
    				if(k==s)
    				{
    					ok=1;
    					break;
    					
    				}	
    			}
    			printf("\n");
    			if(ok)
    				break;
    		}
    	}
    	return 0;
    }
    

    C++ :

    
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <iostream>
    using namespace std;
     
    int day[13]= { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };
     
    int mday[13]= { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; 
     
    int firstday[2055]; 
     
    bool is_spe( int year )
    {
        if( ( year% 4== 0&& year% 100!= 0 )|| year% 400== 0 )
        {
            return true;
        }
        else
        {
            return false;
        }
    }
     
    int main(  )
    {
        firstday[2011]= 6;
        for( int i= 2010; i>= 1; --i )
        {
            int curday= is_spe( i )? 366: 365;
            curday%= 7;
            firstday[i]= firstday[i+ 1]- curday;
            if( firstday[i]<= 0 )  firstday[i]+= 7;
        }
        for( int i= 2012; i<= 2050; ++i )
        {
            int curday= is_spe( i- 1 )? 366: 365;
            curday%= 7;
            firstday[i]= firstday[i- 1]+ curday;
            firstday[i]%= 7;
            if( !firstday[i] )  firstday[i]= 7;
        }
        int year, mon;
        while( scanf( "%d %d", &year, &mon )!= EOF )
        {
            int fday= firstday[year], num_day, sign;
            if( is_spe( year )&& mon> 2 )
            {
                num_day= day[mon- 1];
            }
            else
            {
                num_day= day[mon- 1]- 1;
            }
            sign= ( fday+ num_day )% 7;
            if( !sign )  sign= 7;
            int num_mday= ( is_spe( year )&& mon== 2 )? 29: mday[mon];
            puts( "Su Mo Tu We Th Fr Sa" );
            for( int i= 1; i<= num_mday; ++i )
            {
                int temp= ( sign+ i )% 7;
                for( int j= 0; i== 1&& j< temp; ++j )
                {
                    printf( j== 0? "  ": "   " );
                }
                if( temp== 0 )
                {
                    printf( "%2d", i );
                }
                else if( temp== 6 )
                {
                    printf( "%3d\n", i );
                }
                else
                {
                    printf( "%3d", i );
                }
                if( i== num_mday&& temp!= 6 )
                {
                    puts( "" );
                }
            }
        }
        return 0;
    }
     
     
    
    • 1

    信息

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