题解 | #打印日期#

打印日期

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月份天数
	}
}

全部评论

相关推荐

11-07 16:07
深圳大学 运营
前端飞升:学长,阿里不是卡双非吗,我深也能去吗
点赞 评论 收藏
分享
昨天 14:51
已编辑
井冈山大学 算法工程师
龙虾x:算法比你强的没有你美,比你美的…..算了已经没有比你美的了
工作两年想退休了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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