/*
*程序的版权和版本声明部分:
*Copyright(c)2013,烟台大学计算机学院学生
*All rights reserved.
*文件名称:
*作者:尚振伟
*完成日期:2013年 11月17日
*版本号:v0.1
*对任务及求解方法的描述部分:
*输入描述:无
*问题描述:
*程序输入:2008 5 2
*程序输出:158
*问题分析:
*算法设计:
*/
我的程序:
#include <iostream>
using namespace std;
int date(int,int,int);
int main()
{
int t,year,month,day;
cout<<"请输入你想判断的年月日:"<<endl;
cin>>year>>month>>day;
t=date(year,month,day);
cout<<"该天为本月第"<<t<<"天"<<endl;
return 0;
}
int date(int y,int m,int d)
{
int t=0,i,s=0;
for(i=0;i<=m-1;i++)
{
switch(m)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:s=31;break;
case 4:
case 6:
case 9:
case 11:s=30;break;
case 2:s=28;
}
t+=s;
}
t+=d;
if(m>2&&(y%400==0)||(y%4==0)&&(y%100!=0))
t++;
return t;
}