东软学习小组:夜枫

**

题目:

**
本题要求编写程序计算某年某月某日是该年中的第几天。
输入格式:
输入在一行中按照格式“yyyy/mm/dd”(即“年/月/日”)给出日期。注意:闰年的判别条件是该年年份能被4整除但不能被100整除、或者能被400整除。闰年的2月有29天。
输出格式:
在一行输出日期是该年中的第几天。
输入样例1:
2009/03/02
输出样例1:
61
输入样例2:
2000/03/02
输出样例2:
62

代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include<iostream>
using namespace std;
int main(void){
int run[12]={31,29,31,30,31,30,31,31,30,31,30,31};//闰年的每个月的天数
int ping[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int year,month,day;
int sum=0;//记录总的天数
scanf("%d/%d/%d",&year,&month,&day);//用这种方法输入比较好
if(year%4==0&&year%100!=0||year%400==0){
//run
for(int i=0;i<month-1;i++){//1-month-1的月份,而数组的下标从0开始,b故i<month-1,即从0到month-2;
sum+=run[i];//加上每个月的天数
}
sum+=day;//加上当月当日的天数
cout<<sum<<endl;//输出结束
return 0;
}
else{
//ping
for(int i=0;i<month-1;i++){
sum+=ping[i];
}
sum+=day;
cout<<sum<<endl;
return 0;

}


return 0;
}