题目链接:http://acm.ocrosoft.com/problem.php?cid=1024&pid=0
题目描述
定义一个结构体变量(包括年、月、日)。计算该日在本年中是第几天,注意闰年问题。
输入
年月日
输出
当年第几天
样例输入
2000 12 31
样例输出
366
结构体排序
#include<iostream> using namespace std; int leap[13]={0,31,29,31,30,31,30,31,31,30,31,30,31}; int unleap[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; struct Date{ int year,month,day; }p; bool leapyear(int year){ if(year%400==0||year%4==0&&year%100!=0){ return 1; }else{ return 0; } } int main(){ scanf("%d %d %d",&p.year,&p.month,&p.day); int ans=0; if(leapyear(p.year)){ for(int i=1;i<p.month;i++){ ans+=leap[i]; } }else{ for(int i=1;i<p.month;i++){ ans+=unleap[i]; } } ans+=p.day; cout<<ans<<endl; return 0; }