road420

导航

<2007年7月>
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

统计

常用链接

留言簿(2)

随笔档案

文章档案

搜索

最新评论

阅读排行榜

评论排行榜

万年历

 

// 已知1980年1月1日是星期二!
#include < iostream.h >
#include
< process.h >
#include
< string .h >

struct  Date
{
 
int  year;
 
int  month;
 
int  date;
 
int  day;
 
char  week[ 10 ];
}
;

char   * dweek[ 7 ] = { " Sun " , " Mon " , " Tues " , " Weds " , " Thur " , " Fri " , " Sat " } ;
Date showday(Date pd)
{
 
int  i = 0 ,j = 0 ,k = 0 ,time,score;
 i
= (pd.year - 1980 ) * 365 + (pd.year - 1980 ) / 4 - (pd.year - 1980 ) / 100 + (pd.year - 1980 ) / 400 ;
 i
= i % 7 + 1 ;
 k
= (pd.date - 1 ) % 7
 
if ((pd.year % 100 != 0 ) && (pd.year % 4 == 0 ) || (pd.year % 400 == 0 ))
    
{
     
int  dday1[ 12 ] = { 31 , 29 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 } ;
     
if (pd.month == 2 )   
   
{
        pd.day
= 29 ;
     
if (pd.date > pd.day)
         exit(
0 );
       cout
<< " 该月的天数为: " << pd.day << endl;   
     }

     
else
     
{
    pd.day
= dday1[pd.month - 1 ];
    
if (pd.date > dday1[pd.month - 1 ])
     exit(
0 );
    cout
<< " 该月的天数为: " << pd.day << endl;
   }

    
for (time = 0 ;time < pd.month - 1 ;time ++ )
     j
+= dday1[time];
  j
= j % 7 ;   
  score
= i + j + k + 2 ;
  
if (score < 7 )
    strcpy(pd.week,dweek[score]); 
  
else
  
{
   
while (score >= 7 )
   
{
    score
-= 7 ;
   }

  strcpy(pd.week,dweek[score]); 
  }
    
  cout
<< " 该天的星期数为: " << pd.week << endl;   
  }
 
    
else
    
{
    
int     dday2[ 12 ] = { 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 } ;
  
if (pd.month == 2 )   
   
{
        pd.day
= 28 ;
     
if (pd.date > pd.day)
         exit(
0 );
       cout
<< " 该月的天数为: " << pd.day << endl;   
     }

     
else
     
{
    pd.day
= dday2[pd.month - 1 ];
    
if (pd.date > dday2[pd.month - 1 ])
     exit(
0 );
    cout
<< " 该月的天数为: " << pd.day << endl;
   }

    
for (time = 0 ;time < pd.month - 1 ;time ++ )
     j
+= dday2[time];
  j
= j % 7 ;   
  score
= i + j + k + 2 ;
  
if (score < 7 )
    strcpy(pd.week,dweek[score]); 
  
else
  
{
   
while (score >= 7 )
   
{
    score
-= 7 ;
   }

  strcpy(pd.week,dweek[score]); 
  }
    
  cout
<< " 该天的星期数为: " << pd.week << endl;
  }

return  pd;
}


void  main()
{
    Date obymd;
    obymd.year
= 1980 ;
    obymd.month
= 1 ;
    obymd.date
= 1 ;
    strcpy(obymd.week,dweek[
2 ]);
    cout
<< " 请输入年,月,日: " << "   " ;
    cin
>> obymd.year >> obymd.month >> obymd.date;
    showday(obymd);
}

posted on 2006-05-09 22:03 深邃者 阅读(225) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理