第几天?

 
Problem Description
给定一个日期,输出这个日期是该年的第几天。
 
Input
输入数据有多组,每组占一行,数据格式为YYYY/MM/DD组成,具体参见sample input ,另外,可以向你确保所有的输入数据是合法的。
 
Output
对于每组输入数据,输出一行,表示该日期是该年的第几天。
 
Sample Input
1985/1/20
2006/3/12
 
Sample Output
20
71
 
       
 1 #include<iostream>
 2 #include<cmath>
 3 #include<cstdio>
 4 #include<iomanip>
 5 using namespace std;
 6 bool judge(int year)
 7 {
 8     if((year%4==0&&year%100!=0)||year%400==0) return 1;//条件判断leapyear
 9     else return 0;
10 }
11 struct node
12 {
13     int ans[13];
14     node()
15     {
16         ans[0]=0;ans[1]=31;ans[2]=28;ans[3]=31;ans[4]=30;ans[5]=31;ans[6]=30;ans[7]=31;ans[8]=31;ans[9]=30;ans[10]=31;ans[11]=30;ans[12]=31;
17     }
18     int cal(int x)
19     {
20         int sum=0;
21         for(int i=1;i<x;++i)
22             sum+=ans[i];
23         return sum;
24     }
25 };
26 
27 int main()
28 {
29     int a,b,c;
30     while(scanf("%d/%d/%d",&a,&b,&c)==3)
31     {
32         node s;
33         if(judge(a))  s.ans[2]++;
34         cout<<s.cal(b)+c<<endl;
35     }
36 }
View Code
原文地址:https://www.cnblogs.com/Auroras/p/10794876.html