1251: [Blue Bridge Cup 2015 preliminary round] galaxy bomb

Title Description

Many man-made floating Planet X "bomb" in the vast space of the galaxy in X, used as a landmark in the universe.
After each bomb explosion can be set for how many days.
For example: Alpha bomb placed January 1, 2015, timed to 15 days, then it exploded in January 16, 2015.
There is a beta bomb, a day of b c month placement, the timing is n days, you calculate the exact date of its explosion.
Input
there is an input a plurality of sets of data, each data input line, each line of input four positive integers a, b, c, n
input to ensure dates between 1000-01-01 2020-01-01, date and valid.
not more than 1000 n
output
Please fill in this date, in the format of yyyy-mm-dd i.e. two four year date February 2. For example: 2015-02-19
Please exactly as written. Other words or symbols can not appear.
Sample input
, 2015. 1. 1 15
, 2014 1000. 9. 11
sample output
2015-01-16
2017-08-05

#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
int main()
{
	int leap[2][13]={0,31,28,31,30,31,30,31,31,30,31,30,31,0,31,29,31,30,31,30,31,31,30,31,30,31};
	int y,m,d;
	int n;
	while(scanf("%d %d %d %d",&y,&m,&d,&n)!=EOF){
		while(n>0){
			int t=((y%4==0&&y%100!=0)||(y%400==0));
			n--;
			d++;
			if(d>leap[t][m]){
				d=1;
				m++;
			}
			if(m==13){
				m=1;
				y++;
			}
		}
		if(m<10&&d<10)printf("%d-0%d-0%d\n",y,m,d);
		
		else if(m<10)printf("%d-0%d-%d\n",y,m,d);
		
		else if(d<10)printf("%d-%d-0%d\n",y,m,d);
		
		else printf("%d-%d-%d\n",y,m,d);
	}
}
Released four original articles · won praise 0 · Views 66

Guess you like

Origin blog.csdn.net/qq_44123044/article/details/104333957