0%

[題解]一起回家的日子

a116/ 一起回家的日子

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <bits/stdc++.h>
//#define ll long long
//#define int ll
#define ios ios::sync_with_stdio(0)
#define FOR(i,n) for(int i=0;i<n;i++)
using namespace std;
int t;

int gcd(int a,int b){
if(a==b)return a;

if(a<b)swap(a,b);
while(b!=0){
int c = a%b;
a = b;
b = c;
}
return a;
}

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

void solve(){
int n,arr[100];cin>>n;
for(int i=0;i<n;i++)cin>>arr[i];
int ans = arr[0];
for(int i=1;i<n;i++)ans=(ans*arr[i])/gcd(ans,arr[i]);

int y,m,d;
scanf("%d/%d/%d",&y,&m,&d);

int month[15] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
d+=ans;

while(d>month[m]){
d-=month[m];
if(m==12){
y++;
m = 1;
}
else{
if(leap(y)&&m==2){
d--;
}
m++;
}
}
printf("%04d/%02d/%02d\n",y,m,d);
}

signed main(){
t = 1;
while(t--){
solve();
}
}