题解 | #今年的第几天?#

今年的第几天?

https://www.nowcoder.com/practice/ae7e58fe24b14d1386e13e7d70eaf04d

#include<cstdio>
int main(){
	int year, month, day;
	while (scanf("%d %d %d", &year, &month, &day) != EOF){
		int mon[13] = { 0, 31, 28, 31, 30, 31, 30,31, 31, 30, 31, 30, 31 };
		int totalday[11];
		totalday[0] =0;
		for (int i = 1; i <= 12; i++){
			totalday[i] = totalday[i - 1] + mon[i-1];
		}
		bool isrun = year % 400 == 0 || year % 100 != 0 && year % 4 == 0;
		if (isrun&&month>2){
			printf("%d", totalday[month] + day + 1);
		}
		else{
			printf("%d\n", totalday[month] + day);
		}
	}
}

全部评论

相关推荐

程序员牛肉:这一眼假啊,基本上都是骗人的,不然就涉及到职位贪腐了,就像之前华为的OD事件,看你运气好不好了
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务