题解 | #打印日期#

打印日期

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

#include <iostream>
using namespace std;
#include <iomanip>
int month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int main(){
	int y,n,flag = 0;
	while(cin >>y>>n){
		int i,temp = n;
		//判断闰年
		if (y % 4 == 0 && y %100 != 0 || y%400 == 0){
            month[2]=29;
        }
		for(i = 1; temp>0; i++){//i 月份
			if (temp>month[i])
				temp-=month[i];
			else break;
		}
		
		cout << y <<"-"<< setw(2) <<setfill('0')<<i<<"-"<< setw(2) <<setfill('0')<<temp<<endl;
        month[2] = 28;//还原2月份天数
	}
}

全部评论

相关推荐

06-19 19:06
门头沟学院 Java
点赞 评论 收藏
分享
05-26 22:25
门头沟学院 Java
Java小肖:不会是想叫你过去把你打一顿吧,哈哈哈
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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