Untitled

mail@pastecode.io avatar
unknown
c_cpp
21 days ago
904 B
3
Indexable
Never
#include <stdio.h>
using namespace std;

int find(int a,int b);

bool check(int x);

int get_day(int m, int y) {
    int day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    if(check(y) && m==2) {
        return 29;
    }
    else {
        return day[m];
    }
}

int main(){
	int n,a,yy,mm,dd;
	scanf("%d",&n);
	int child[n],day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
	for(int i=0;i<n;i++){
		scanf("%d",&child[i]);
	}
	scanf("%d/%d/%d",&yy,&mm,&dd);
	a=child[0];
	for(int i=1;i<n;i++){
		a=find(a,child[i]);
	}
	dd+=a;
	while(dd> get_day(mm, yy)){
		dd-= get_day(mm, yy);
		if(mm==12){
			mm=1;
			yy++;
		}
		else {
			// if(mm==2&&check(yy))dd--;
			mm++;
		}
	}
	printf("%04d/%02d/%02d",yy,mm,dd);
}

int find(int a,int b){
	if(b>a){
		int t=b;
		b=a;
		a=t;
	}
	int k=a;
	while(a%b!=0){
		a+=k;
	}
	return a;
}

bool check(int x){
	if((x%100!=0||x%400==0)&&x%4==0)return 1;
	else return 0;
}
Leave a Comment