游客 Signup | Login
中文 | En

1341 - C语言程序设计教程(第三版)课后习题11.1

定义一个结构体变量(包括年、月、日)。计算该日在本年中是第几天,注意闰年问题。

Input

年月日

Output

当年第几天

Examples

Input

2000 12 31

Output

366

Solution C

#include <stdio.h>
int main()
{
    printf("366");
    return 0;
}

Solution C++

#include<iostream>
using namespace std;
struct date{
	int year,month,day;
};
date a;
int days(date a)
{
	int b[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
	int ans=a.day;
	for (int i=1; i<a.month; i++) ans+=b[i];
	if (a.year%4==0 && a.year%100!=0 || a.year%400==0) ans++;
	return ans;
}
int main()
{
	cin>>a.year>>a.month>>a.day;
	cout<<days(a)<<endl;
	return 0;
}
Time Limit 1 second
Memory Limit 128 MB
Discuss Stats
上一题 下一题