You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# include <bits/stdc++.h>
using namespace std ;
// 判断闰年的函数
int run ( int year ) {
// 闰年判断条件: 能被4整除但不能被100整除, 或者能被400整除
if ( ( year % 4 = = 0 & & year % 100 ! = 0 ) | | year % 400 = = 0 ) {
return 1 ; // 是闰年返回1
} else {
return 0 ; // 不是闰年返回020
}
}
// 计算指定月份之前的总天数
int mon ( int y , int m ) {
int days = 0 ;
// 存储每个月的天数
int monthDays [ 13 ] = { 0 , 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 } ;
// 如果是闰年, 2月改为29天
if ( run ( y ) ) {
monthDays [ 2 ] = 29 ;
}
// 累加月份之前的天数
for ( int i = 1 ; i < m ; i + + ) {
days + = monthDays [ i ] ;
}
return days ;
}
int main ( )
{
// y-年, m-月,d-日, n-第几天
int y , m , d , n ;
n = 0 ;
// 请在此添加代码,计算并输出指定日期是第几天
/********** Begin *********/
cin > > y > > m > > d ;
n = mon ( y , m ) + d ; // 月份之前的天数 + 当月天数
/********** End **********/
printf ( " %d-%d-%d是第%d天 \n " , y , m , d , n ) ;
return 0 ;
}